$_FILES Array and its Confusing Structure

Have you ever noticed that the $_FILES array has an extremely odd structure that isn’t the usual type of array. The script i wrote helps to put it in an order so you can simply step through each one without having to write any sort of confusing loop.

It’s implementation can be seen below:

// a file field with the name image[] was passed
//if it were a non array input it would simply be if (!empty($files['image']))...
$files = change_file_array($_FILES);
if (!empty($files))
foreach ($files['image'] as $key => $f)
if ($f['error'] == 0 && $f['size'] > 0)
//do somethign with file here

I’m still getting used to wordpresses editor sorry about the indenting.

Click here download the script.

You can leave a response, or trackback from your own site.

Leave a Reply