views:

31

answers:

3

I have the following form that uses some jQuery to allow an array of files to be submitted:

<form enctype="multipart/form-data" action="index.php" method="post" >
<input type="file" class="multi" name="test[]"  />
<input  type="submit" value="submit" name="submit" />
</form>

When I use method="get" I get the following URL when submitted:

http://website.com/index.php?test[]=image.jpg&amp;test[]=image2.jpg&amp;submit=submit

How do I gather the test[] array data using $_POST and/or $_FILE using method="post"?

+1  A: 

This becomes an array on the server-end, and as such you can cycle through the values with a loop. Below is an example using the foreach loop:

foreach ($_FILES["test"] as $file) {
  // handle current file
}
Jonathan Sampson
+1  A: 

You need to always submit file uploads with POST.

You then access the files on the server side via the $_FILES array.

Tizag.com has a good tutorial on file uploads.

Jacob Relkin
+1  A: 

a more flexible way to access the $_FILES if you dont know the input name

i did this one

$files = $_FILES;
foreach($files as $key =>$file)
{
 $uploaded["filename"] = $files[$key]["name"];
}

print_r($uploaded);

would print the filename

streetparade