$_FILES array and its silly structure

Viewed 22157

Possible Duplicate:
How do you loop through $_FILES array?

For some reason arrays really get to me. I can get there in the end, but this $_FILES array seems to be backwards to me.

I want to be able to loop through $_FILES like so:

foreach($_FILES as $file)
{
   echo $file['name'] . "<br>";
   echo $file['type'] . "<br>";
   echo $file['size'] . "<br>";
   echo $file['error'] . "<br>";
}

But obviously with the way its structured you cannot do that. So I have written 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 winded and rediculous but my mind is stuck at the moment as to how to loop through properly the different parts of this array to get it work and loop the way I want it to.

There must be a better way?

Please help!

2 Answers
Related