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

?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.