1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Uploading Files

Discussion in 'PHP' started by infostations, Jan 22, 2011.

  1. #1
    So on my site users are allowed to upload images, i recently found this new html 5 feature that allows you to allows users to upload multiple files at once using "multiple="multiple"" but the promblem i dont know how to habdle uploading the images if they select more then one file
     
    infostations, Jan 22, 2011 IP
  2. Martin K

    Martin K Active Member

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    "multiple="multiple"" store the data in array so you just have to loop through it with foreach or something else.
     
    Martin K, Jan 22, 2011 IP
  3. infostations

    infostations Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i tired foreaching but i just dont really understand it, could u possible give an example
     
    infostations, Jan 22, 2011 IP
  4. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #4
    When you upload a file the information regarding that file is stored in the $_FILES superglobal. Upon uploading multiple files, you may want to output the contents of the array to see what it contains:

    print_r( $_FILES );
    PHP:
    To upload multple files on the server, you would have to loop through the array, and process each file. For example:

    foreach( $_FILES as $File ) {
        /* $File is an array.
            Keys: name => name of file sent by browser, type => type of file, tmp_name => location of file which is temporarily stored on the server, error => contains error code, size => size of file in bytes
        */
    }
    
    PHP:
    You would perform various checks and then use the move_uploaded_file function to move the file to a more permanent location.
    }
     
    Alex Roxon, Jan 22, 2011 IP