Jump to content

[SOLVED] PHP Move_Uploaded_File


sh0wtym3

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");
       }

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.