Possible duplicate:
How to loop through the $ _FILES array?
For some reason, arrays really reach me. I can get there, but this $ _FILES array seems to me the opposite.
I want to be able to scroll $ _FILES like this:
foreach($_FILES as $file)
{
echo $file['name'] . "<br>";
echo $file['type'] . "<br>";
echo $file['size'] . "<br>";
echo $file['error'] . "<br>";
}
But obviously, with its structured structure you cannot do this. So I wrote the following:
echo "<pre>";
$x=0;
$file = array();
foreach($_FILES['attachment']['name'] as $data)
{ $file[$x]=array();
array_push($file[$x],$data); $x++;
}
$x=0;
foreach($_FILES['attachment']['type'] as $data)
{ array_push($file[$x],$data); $x++;}
$x=0;
foreach($_FILES['attachment']['tmp_name'] as $data)
{ array_push($file[$x],$data); $x++;}
$x=0;
foreach($_FILES['attachment']['error'] as $data)
{ array_push($file[$x],$data); $x++;}
$x=0;
foreach($_FILES['attachment']['size'] as $data)
{ array_push($file[$x],$data); $x++;}
var_dump($file);
echo "</pre>";
Which seems very long and thoughtful, but my mind is stuck at the moment about how to correctly iterate over different parts of this array in order to make it work and work the way I want it to.
Should there be a better way?
Please, help!
source
share