Skip to content

Instantly share code, notes, and snippets.

@Luciaisacomputer
Created April 26, 2016 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Luciaisacomputer/f072988640dd87ef43b8965ba4faa9ba to your computer and use it in GitHub Desktop.
Save Luciaisacomputer/f072988640dd87ef43b8965ba4faa9ba to your computer and use it in GitHub Desktop.
This helps make the $_FILES global array less clunky and easier to iterate over
<?php
function reArrayFiles(&$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;
}
?>
<?php
$file_ary = reArrayFiles($_FILES['contentUploads']);
foreach ($file_ary as $file) {
print $file['name'];
print $file['type'];
print $file['size'];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment