Skip to content

Instantly share code, notes, and snippets.

@Dennis14e
Created July 28, 2021 21:36
Show Gist options
  • Select an option

  • Save Dennis14e/fc0cdbb37375cdb5be8d1c11a1823a0b to your computer and use it in GitHub Desktop.

Select an option

Save Dennis14e/fc0cdbb37375cdb5be8d1c11a1823a0b to your computer and use it in GitHub Desktop.
PHP: Rearrange $_FILES array
<?php
function rearrangeFiles($files)
{
$ret = [];
foreach ($files as $name => $keys) {
if (!is_array($keys['name'])) {
$ret[$name] = [ $keys ];
continue;
}
foreach (array_keys($keys['name']) as $key) {
$ret[$name][$key] = [
'name' => $keys['name'][$key],
'type' => $keys['type'][$key],
'tmp_name' => $keys['tmp_name'][$key],
'error' => $keys['error'][$key],
'size' => $keys['size'][$key],
];
}
}
return $ret;
}
$_FILES = rearrangeFiles($_FILES);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment