mac007 Posted August 3, 2008 Share Posted August 3, 2008 Hello, all: I thought I could convert a basic upload script into a MULTIPLE file upload by simply adding a FOREACH loop to it, but doesnt seem to do it. Not sure if I am setting it up correctly. It looks like it does recognize the array since it does give me the "There was an error uploading the file..." warning three times. Appreciate any help on this! Here is the html form and php code ( all residing in same page): <? if (isset($_POST[submit])) { $uploadArray= array(); $uploadArray[] = $_POST['uploadedfile']; $uploadArray[] = $_POST['uploadedfile2']; $uploadArray[] = $_POST['uploadedfile3']; foreach($uploadArray as $file) { $target_path = "upload/"; $target_path = $target_path . basename( $_FILES['$file']['name']); if(move_uploaded_file($_FILES['$file']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['$file']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body> <form enctype="multipart/form-data" action="upload-simple.php" method="POST"> <p> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /> </p> <p>Choose a file to upload: <input name="uploadedfile2" type="file" /> </p> <p>Choose a file to upload: <input name="uploadedfile3" type="file" /> <br /> <input name="submit" type="submit" id="submit" value="submit" /> </p> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/117943-how-to-do-multiple-file-upload-through-an-array/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 3, 2008 Share Posted August 3, 2008 Your existing code is not forming $file in $_FILES['$file']... correctly because the names of the form fields don't exist as $_POST variables. Also, the single-quotes around '$file' will prevent the variable from being parsed. There is an example of how to do multi-file uploads in the php manual - http://www.php.net/manual/en/features.file-upload.multiple.php Link to comment https://forums.phpfreaks.com/topic/117943-how-to-do-multiple-file-upload-through-an-array/#findComment-606693 Share on other sites More sharing options...
mac007 Posted August 3, 2008 Author Share Posted August 3, 2008 Thanks.. gonna check your link and see if I can work it out! Link to comment https://forums.phpfreaks.com/topic/117943-how-to-do-multiple-file-upload-through-an-array/#findComment-607006 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.