note 114087 added to reserved.variables.files
| From: | badandyomega at gmail dot com | Date: | Fri, 10 Jan 2014 01:27:15 +0000 |
| Subject: | note 114087 added to reserved.variables.files | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198180@lists.php.net to get a copy of this message | ||
Others have posted about how the $_FILES array organizes data differently depending on whether the
HTML input is a single or multiple type, so it seems to be a common enough problem. If for some
reason you need to mix-and-match the types, or you're not sure which how many files you'll
be expecting from a multiple input, this is a very useful way to reorganize the $_FILES array.
Also, unlike some of the earlier posts, the formatting of the new array (i.e. the number of keys and
values) is consistent.
<?php
// Reorganize $_FILES array information
$files = Array ();
$i = 0;
// Start with all inputs in $_FILES array
foreach ($_FILES as $input)
{
$j = 0;
foreach ($input as $property => $value)
{
if (is_array($value))
{
$j = count($value); // Number of iterations
for ($k = 0; $k < $j; ++$k)
{
$files[$i + $k][$property] = $value[$k];
}
}
else
{
$j = 1;
$files[$i][$property] = $value;
}
}
$i += $j;
}
?>
The results will look something like this:
$files = Array (
[0] => Array (
[name] => ''
[type] => ''
[tmp_name] => ''
[error] => 0
[size] => 0
)
)
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/reserved.variables.files.php
Edit -- https://master.php.net/note/edit/114087
Del: integrated -- https://master.php.net/note/delete/114087/integrated
Del: useless -- https://master.php.net/note/delete/114087/useless
Del: bad code -- https://master.php.net/note/delete/114087/bad+code
Del: spam -- https://master.php.net/note/delete/114087/spam
Del: non-english -- https://master.php.net/note/delete/114087/non-english
Del: in docs -- https://master.php.net/note/delete/114087/in+docs
Del: other reasons-- https://master.php.net/note/delete/114087
Reject -- https://master.php.net/note/reject/114087
Search -- https://master.php.net/manage/user-notes.php