Results 1 to 4 of 4

Thread: Mulitple file uplaod

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Mulitple file uplaod

    How easy is it?

    Say i wanted to uplaod 10 files at a time how do i got about doing it?

  2. #2
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: Mulitple file uplaod

    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Mulitple file uplaod

    Its actually quite easy you give each file the same name and append square brakets to it. This will make it an array in PHP:
    HTML Code:
    <p>File 1: <input name="files[]" type="file" /></p>
    <p>File 2: <input name="files[]" type="file" /></p>
    <p>File 3: <input name="files[]" type="file" /></p>
    The file array can then be accessed by means of the following:

    $_FILES['files']['name'][0]
    $_FILES['files']['name'][1]

    Have a look here for an example: http://uk.php.net/manual/en/features...d.multiple.php
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #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