Multiple file uploads, PHP Form

Discussion in 'PHP' started by onlyican.com, Dec 9, 2005.

  1. #1
    Hey Guys

    I need some help

    I am making a form, to upload multiple files to a directory.

    I can't seem to get the form to do multiple file uploads.

    On the send page, I have went back to upload one file. Could someone help me out. I would like an option for up 2 3 files to be uploaded.

    Here is the code for the form

    <?php
    
    function showForm() {
    echo "<html><head>\n"
     ."<title>File Upload</title>\n"
     ."</head><body>\n"
     ."<font face='arial' size='1'>\n"
     ."<h3>Send your Image</h3>\n"
     ."<form enctype='multipart/form-data' action='thank_you.php' method='POST' name=send_file>\n"
     ."<table width='100%' border='0' cellpadding='0' cellspacing='4'>\n"
     ."<tr>\n"
     ."<td width='25%'>Choose the 1st file to upload:</td>\n"
     ."<td width='75%'><input name='uploadedfile' type='file' /></td>\n"
     ."</tr><tr>\n"
     ."<td width='25%'>Choose the 2nd file to upload:</td> \n"
     ."<td width='75%'><input name='uploadfile2' type='file' /></td>\n"
     ."</tr><tr>\n"
     ."<td width='25%'>Choose the 3rd file to upload:</td>\n"
     ."<td width='75%'><input name='uploadfile3' type='file'></td>\n"
     ."</tr><tr>\n"
     ."</tr></table>\n"
     ."<input type='submit' value='Send Your File' />\n"
     ."<input type='reset' value='Clear' />\n"
     ."</form></font></body></html>\n";
    }
     
     showForm();
    ?>
    PHP:
    And here is the other page

    <?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']);
    
    // This is how we will get the temporary file...
    $_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 "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded to the creative department.<br><br><a href='index.php'>Click Here</a> to go back to upload another file.";
    
    } else{
        echo "There was an error uploading the file, please <a href='index.php'>click here</a> to go back and try again. ";
    }
    ?>
    PHP:
     
    onlyican.com, Dec 9, 2005 IP
  2. himambo

    himambo Peon

    Messages:
    100
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    see this tutorial
    http://www.phpeasystep.com/workshopview.php?id=2
     
    himambo, Dec 10, 2005 IP