SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to handle this array?

    I have a multiple file upload that puts the $_FILES into a $image[] array. On the processing page, I have a script that uploads the files- I need to modify it to have it echo the specific file names as it goes through the array. I am close.. need to be able to print the file name of each $image[] in the file upload. Please see my last commented line below:


    Here is my multiple upload form:

    Code:
    <input type=file name='images[]'><br>
    <input type=file name='images[]'><br>
    <input type="submit" name="Submit" value="Submit">
    Here is my script to accept the images[]; array
    PHP Code:
    while(list($key,$value) = each($_FILES[images][name]))
            {
                if(!empty(
    $value))
                {
                    
    $filename $value;
                        
    $add "upload/$filename";

                        
    copy($_FILES[images][tmp_name][$key], $add);
                        
    chmod("$add",0777);
                
                    
                }
            }

    /// How can I echo this- so each file upload can be called uniquely from an array?
     
    echo "You uploaded: $image[0]";    //         <--------------------------------NEED HELP HERE
     
    echo "You uploaded: $image[1]";    //         <--------------------------------NEED HELP HERE 

  2. #2
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What error are you getting?

    Put the array variables in {}

  3. #3
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This returns nothing:
    PHP Code:
    echo "You uploaded: $image[0]";   
    echo 
    "You uploaded: $image[1]"
    How can i echo the file name of each image uploaded from the $_FILES[images][name]?

    Like this?
    PHP Code:
    echo $_FILES[images][0];
    echo 
    $_FILES[images][1]; 

  4. #4
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo $_FILES['images'][0]['name'];
    ... 

  5. #5
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm thats not working..

  6. #6
    Team SitePoint santouras's Avatar
    Join Date
    Jul 2006
    Location
    planet earth
    Posts
    273
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    my utility belt tells me its to the bar batman

    read the manual then google it then do a search THEN post....

  7. #7
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    while(list($key,$value) = each($_FILES['images']['name'])){
      if(!empty(
    $value)){
        
    $filename $value;
        
    $add "upload/$filename";
        
    copy($_FILES['images']['tmp_name'][$key], $add);
        echo 
    "You uploaded: $value<br />\n";
        }
      } 
    my mobile portal
    ghiris.ro

  8. #8
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured it out. Here is the complete upload script to upload muliple files. Warning, there are no file size or type restrictions. Hope this helps someone..


    Add as many uploads as you want on this form
    HTML Code:
    <form  action="./upload-mult.php" method="post" enctype="multipart/form-data" >
    	File 1: <input type=file name='images[]' class='bginput'><br>
    	File 2: <input type=file name='images[]' class='bginput'><br>
    	<input type="submit" name="Submit" value="Submit">
    </form>
    upload-mult.php - this uploads files and prints their filename.
    PHP Code:
    <?php
    // FILE UPLOAD //
    while(list($key,$value) = each($_FILES[images][name]))
            {
                if(!empty(
    $value))
                {
                    
    $filename $value;
                        
    $add "./images/$filename";
                        
    copy($_FILES[images][tmp_name][$key], $add);
                        
    chmod("$add",0777);
                
                    
                }
    //$value            
    }
    echo 
    "Files Uploaded:<br>";
    echo 
    $_FILES['images']['name'][0]."<br>";
    echo 
    $_FILES['images']['name'][1];
    ?>
    Last edited by ripcurlksm; Nov 11, 2007 at 19:46.


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
  •