开发者

Multiple file uploader $_POST issue

开发者 https://www.devze.com 2022-12-18 06:09 出处:网络
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\" >

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&test[]=image2.jpg&submit=submit

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


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


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
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消