Results 1 to 4 of 4

Thread: Mulitple file uplaod

Threaded View

  1. #4
    New Member
    Join Date
    Jun 2005
    Location
    usa
    Posts
    2

    Re: Mulitple file uplaod

    here is a 3 page code-set to do as many uploads as you wish .. i got it somewhere a while ago and use it daily .. i dont remember who to give credit to for it ... sorry.

    customize them as per your functionality needs and aesthetic formatting.

    uploadForm1.php will ask you how many uplaods you want to do ... simply enter an integer between 1 and 99 (this can be changed if you need more than 99 by altering the uploadNeed maxlength variable which is 2 charactors by default, but your server might time you out on many uploads or a few with very large file sizes.)

    uploadForm2.php processes the input from uploadNeed from uploadForm1.php and displays the the requested amount of file upload/browse boxes. This is where you enter the local file path or click browse to broswe to your local file path and click on file to upload.

    processFiles.php does the meaty work in uploading. When the uploads complete you will get a confirmation of success or failure in the upload process.

    remember that if you are trying to overwrite a file, you cant do it without the appropriate write/delete file permissions on the server.




    uploadForm1.php

    <html>
    <head>
    <title># of Files to Upload</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <form name="form1" method="post" action="uploadForm2.php">
    <p>Enter the number of files to upload (Max=99 Default=1), then click Submit.</p>
    <p>
    <input name="uploadNeed" type="text" id="uploadNeed" maxlength="2" value="1">
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </form>
    </body>
    </html>




    uploadForm2.php

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>

    <form name="form1" enctype="multipart/form-data" method="post" action="processFiles.php">
    <p>
    <?
    // start of dynamic form
    $uploadNeed = $_POST['uploadNeed'];
    for($x=0;$x<$uploadNeed;$x++){
    ?>
    <input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>">
    </p>
    <?
    // end of for loop
    }
    ?>
    Click the browse button and browse to the location your file resides, and click on the file to select it for uploading.<br><br>
    <p><input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>">
    <input type="submit" name="Submit" value="Submit"><br><br>
    after all the files are selected, click the Submit button and wait for it to upload.
    <br><br>
    DO NOT click Submit more than once or it may interfere with the upload progress.
    <br><br>
    When the file uploading is complete, you will get a message stating success or failure.
    </p>
    </form>
    </body>
    </html>




    processFiles.php

    <?
    $uploadNeed = $_POST['uploadNeed'];
    // start for loop
    for($x=0;$x<$uploadNeed;$x++){
    $file_name = $_FILES['uploadFile'. $x]['name'];
    // strip file_name of slashes
    $file_name = stripslashes($file_name);
    $file_name = str_replace("'","",$file_name);
    $copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);
    // check if successfully copied
    if($copy){
    echo "$file_name | uploaded sucessfully!<br>";
    }else{
    echo "$file_name | could not be uploaded!<br>";
    }
    } // end of loop
    ?>
    Last edited by bind; Jun 21st, 2005 at 07:37 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width