I currently have one file upload working but I need two on one page. I have replicated the following code twice but this means the first upload works but the second one throws the else error message.

How could I make this code acceptable for 2 uploads:

<?php
// Where the file is going to be placed 
$target_path = "uploads/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "". basename($_SESSION ['filename'] = $_FILES['uploadedfile']['name'])."" ; } else{ echo "There was an error uploading the file, please try again!"; } ?>

    You either need to give the <input type="file"> fields different names, and then access them separately a $FILES['name1']['tmp_name'] and $FILES['name2']['tmp_name']; or else give them the same name but with a "[]" at the end of the name, then access them by an additional array index, e.g.: $FILES['name']['tmp_name'][0] and $FILES['name']['tmp_name'][1].

      How could I make this code acceptable for 2 uploads:

      hi
      you are on the right track, my friend.
      But I think you will find more, the best and the correct way
      here in PHP Manual = http://docs.php.net/

      They have a Category discussing File Upload.
      With readers comments, examples and submitted scripts.
      And even a special chapter you should read 🆒
      Uploading multiple files
      Multiple files can be uploaded using different name for input

      Regards 🙂
      halojoy - your php helper & a good friend

        Write a Reply...