Results 1 to 6 of 6

Thread: How to Upload Multiple Files in PHP?

  1. #1
    Join Date
    Jul 2006
    Posts
    182

    How to Upload Multiple Files in PHP?

    Hi friends,
    Your last time help was really grateful, so I thought to post my queries on this forum. Now I am stuck while uploading the multiple files in PHP. I know to upload a single file, but when it comes to multiple I get screwed. I have tried to do lot of different things but was not getting an appropriate results. So please tell me how to Upload Multiple Files in PHP? Hope that someone would reply me soon.!!
    "Yea though I walk through the valley of the shadow of death... I will fear no evil." -Psalms 23

    K8N Diamond Plus (BIOS v1.2)
    AMD Athlon 64 X2 4400+
    Antec TruControl 550W
    NVidia GeForce 7900GT (NGO v1.8466 BETA)
    OCZ Platinum 2x1GB (2-3-2-5)
    SATA: WD740
    PATA: 2xWD2500, WD1200, NEC DVD/RW

  2. #2
    Join Date
    Aug 2006
    Posts
    235

    Re: How to Upload Multiple Files in PHP?

    Downloading multiple files is possible using different names in the name attribute of the input tag. It is also possible to download multiple files simultaneously and obtain information in tabular form. For this you must use the syntax table in the HTML tag names, same as multiple selections and checkboxes.
    HTML Code:
    <form action="file-upload.php" method="post" enctype="multipart/form-data"> Upload multiple files: <br /> 
    <input name="userfile[]" type="file" /> <br /> 
    <input name="userfile[]" type="file" /> <br /> 
    <input type="submit" value="Send the value" /> 
    </ form>
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  3. #3
    Join Date
    Aug 2006
    Posts
    227

    Re: How to Upload Multiple Files in PHP?

    When you submit the form which is provided by the 'MELTRONICS', the arrays $ _FILES [ 'userfile'], $ _FILES [ 'userfile'] [ 'name'] and $ _FILES [ 'userfile'] [ 'size'] will be initialized. $ _FILES is a Variable File Download via HTTP. An associative array of values downloaded to the current script via HTTP POST method. $ _FILES Contains the same information, but is not superglobal. This is a 'superglobal', or automatic global, variable. This simply means that it is available in all contexts of the script. It is not necessary to do global $ variable to access it within functions or methods.
    I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.

  4. #4
    Join Date
    Mar 2008
    Posts
    349

    Re: How to Upload Multiple Files in PHP?

    Lets take an example, so that it would be easy for you to understand. Suppose the file / home / test / Demo1.html and / home / test / Demo2.out have been downloaded. In this case, $ _FILES [ 'userfile'] [ 'name'] [0] contains Demo1.html and $ _FILES [ 'userfile'] [ 'name'] [1] contains Demo2.out. Where $ _FILES Contains the same information, but is not superglobal. Note that $ _FILES and $ _POST are different variables and that PHP handles them. Ensure that filename is a file downloaded by HTTP POST. If the file is valid, it is moved to destination.

  5. #5
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to Upload Multiple Files in PHP?

    I am providing you with the script of PHP to upload the multiple files. The following script demonstrates the same.
    PHP Code:
    while(list($key,$value) = each($_FILES[images][name]))
    {
    if(!empty(
    $value)){   
    $filename $value;   

    $filename=str_replace(" ","_",$filename);

    $add "upimg/$filename";   
    //echo $_FILES[images][type][$key];     
    // echo "<br>";                           
    copy($_FILES[images][tmp_name][$key], $add);     
    chmod("$add",077);                
    }


  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: How to Upload Multiple Files in PHP?

    There is not much difference in uploading multiple files in PHP when compared to uploading a single file. Here is how the HTML code would look with multiple file uploads :
    HTML Code:
    <form enctype="multipart/form-data" action="<?php echo $PHP_SELF;?>" method="POST">
    File 1: <input name="file[]" type="file"><br>
    File 2: <input name="file[]" type="file"><br>
    File 3: <input name="file[]" type="file"><br><br>
    <input type="submit" value="Submit">
    </form>
    And the PHP Script would be :
    PHP Code:
    <?php

    for($i 0$i != 5$i++)
    {

            if(
    is_uploaded_file($_FILES["file"]["tmp_name"][$i]))
            {

                    echo 
    "tmp_name: ".$_FILES["file"]["tmp_name"][$i]."<br>";

                    echo 
    "name: ".$_FILES["file"]["name"][$i]."<br>";

                    echo 
    "size: ".$_FILES["file"]["size"][$i]."<br>";

                    echo 
    "<br><br>";

            }

    }

    ?>

Similar Threads

  1. Why can’t we upload 2 GB files on Nokia N8?
    By Vicky Woodley in forum Portable Devices
    Replies: 4
    Last Post: 29-11-2010, 09:19 AM
  2. Multiple site simultaneous upload
    By Character in forum Technology & Internet
    Replies: 7
    Last Post: 27-07-2010, 11:01 PM
  3. Combine multiple ftp servers to increase upload speed
    By 2ndChance in forum Networking & Security
    Replies: 7
    Last Post: 13-05-2010, 06:34 PM
  4. Replies: 3
    Last Post: 14-05-2009, 10:25 AM
  5. Upload Files in ASP.NET
    By Ariadne in forum Software Development
    Replies: 3
    Last Post: 15-01-2009, 07:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,241,437.48646 seconds with 17 queries