sh0wtym3 Posted October 31, 2008 Share Posted October 31, 2008 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 More sharing options...
wildteen88 Posted October 31, 2008 Share Posted October 31, 2008 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"); } Link to comment https://forums.phpfreaks.com/topic/130934-solved-php-move_uploaded_file/#findComment-679699 Share on other sites More sharing options...
sh0wtym3 Posted October 31, 2008 Author Share Posted October 31, 2008 Ah, simple enough. Thanks man... I'm still learning. Link to comment https://forums.phpfreaks.com/topic/130934-solved-php-move_uploaded_file/#findComment-679704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.