Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Snippet / function that rearrange php files when doing file uploads
* Takes the input file element name, e.g. `$files = rearrange_files($_FILES['files']);`
* If you have a file input like this `<input type="file" name="files[]" multiple >`
* Will return an array where each element is a single file. Much more convenient thant
* Using the PHP $_FILES array
function rearrange_files($file_post) {
$file_ary = array();
$file_count = count($file_post['name']);
$file_keys = array_keys($file_post);
for ($i=0; $i< $file_count; $i++) {
foreach ($file_keys as $key) {
$file_ary[$i][$key] = $file_post[$key][$i];
return $file_ary;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment