Jump to content

convert single-file upload script to multiple-file...


mac007

Recommended Posts

Hello, all: been trying to convert this little single-file upload to multiple by naming each file form-field as "userfile[]" as it's supposed to automatically treat them as an array.. but no luck!  Can you guide me as to what am I doing wrong??

appreciate the help!

 

 

<?php

if (!isset($_REQUEST["seenform"])) {
?>
   <form enctype="multipart/form-data" action="#" method="post">
   Upload file: <input name="userfile[]" type="file" id="userfile[]">
   Upload file: <input name="userfile[]" type="file" id="userfile[]">
   <input type="submit" value="Upload">
   <input type="hidden" name="seenform">
   </form>
<?php
} 
else 
{ // upload begins
$userfiles = array($_FILES['userfile']);
foreach ($userfiles as $userfile)
{ // foreach begins
   $uploaded_dir = "uploads/";
   $userfile = $_FILES['userfile']["name"];
   $path = $uploaded_dir . $userfile;
   if (move_uploaded_file($_FILES['userfile']["tmp_name"], $path)) 
  	 	{
	 	 print "$userfile file moved";
	  	// do something with the file here
   		} else 
		{
	  	print "Move failed";
		}
		} // foreach ends
} // upload ends

?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.