Jump to content

Recommended Posts

Hey,

 

I have a script that uploads a file to a specific directory, and it runs like a charm. However I need to expand it to upload 2 files, to 2 different directories. I modified the entire script but have a question about the last part, shown below:

 

 // Upload the file to your specified path.
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $new_file_name)) {
         header("Location: http://mysite.com/members.php?cmd=success"); 
	 }
  else
         echo 'There was an error during the file upload.  Please try again.'; // It failed .

 

The 2nd file has the name 'userfile2', and is being uploaded to $upload_path2, so I modified the script (shown below):

 

   // Upload the file to your specified path.
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $new_file_name)) {
         header("Location: http://mysite.com/members.php?cmd=success"); 
	 }
if(move_uploaded_file($_FILES['userfile2']['tmp_name'],$upload_path2 . $new_file_name2)) {
         header("Location: http://mysite.com/members.php?cmd=success"); 
	 }
      else
         echo 'There was an error during the file upload.  Please try again.'; // It failed .

 

I have a feeling this isn't going to work, since after the first upload ('userfile') the header will redirect the user. How do I go about accomplishing this multiple file upload?

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/130934-solved-php-move_uploaded_file/
Share on other sites

Change

if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $new_file_name)) {
         header("Location: http://mysite.com/members.php?cmd=success");
       }
   if(move_uploaded_file($_FILES['userfile2']['tmp_name'],$upload_path2 . $new_file_name2)) {
         header("Location: http://mysite.com/members.php?cmd=success");
       }

 

to

if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $new_file_name) && move_uploaded_file($_FILES['userfile2']['tmp_name'],$upload_path2 . $new_file_name2)) {
         header("Location: http://mysite.com/members.php?cmd=success");
       }

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.