RE: Multiple file upload
| From: | Huy Nguyen | Date: | Wed, 11 Nov 2009 15:51:19 +0000 |
| Subject: | RE: Multiple file upload | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-299774@lists.php.net to get a copy of this message | ||
Do you mean 3 forms, each having a file upload input? Or 1 form with 3 file upload inputs?
If you have 3 forms, then the user can only submit one form at a time. So your $_FILES would
contain only one file.
If you have one form with 3 file upload, it depends on if they are the same name for the file input
- whether they all are "UPLOADIMAGE[]", or each one is "UPLOADIMAGE1",
"UPLOADIMAGE2", "UPLOADIMAGE3", etc.
-----Original Message-----
From: Matthew Croud [mailto:matt@obviousdigital.com]
Sent: Wednesday, November 11, 2009 9:10 AM
To: PHP General list
Subject: Multiple file upload
Dear lords of PHP,
I have a working image upload script that meets all my needs,
My question is I need to upload multiple images using the same form,
This is the PHP part I have so far, largely taken from a book:
_________________________________________________________
$file_dir = "/public_html/uploads";
foreach($_FILES as $file_name => $file_array) {
echo "path: ".$file_array["tmp_name"]."<br/>\n";
echo "name: ".$file_array["name"]."<br/>\n";
$UploadName = $file_array["name"];
if (is_uploaded_file($file_array["tmp_name"])) {
move_uploaded_file($file_array["tmp_name"], "$file_dir/".
$file_array["name"]) or die ("Couldn't copy");
echo "file was moved!<br/>";
}
}
_________________________________________________________
Lets say the HTML from that sends data to this script has 3 upload
forms that get send to $_FILES, would I access the data by modifying
the following line from the above example:
...
foreach($_FILES[' UPLOADIMAGE1 '] as $file_name => $file_array) {
...
...
foreach($_FILES[' UPLOADIMAGE2 '] as $file_name => $file_array) {
...
...
foreach($_FILES[' UPLOADIMAGE3 '] as $file_name => $file_array) {
...
Thanks for reading!
Matt Cheezoid