$_files Subarrays

Discussion in 'PHP' started by lkenn, Feb 12, 2013.

  1. #1
    I am new to this so this is probably a stupid question but, how do I access [userfile1] and [userfile2] in the following code to write a foreach statement that runs on each of those arrays in $_FILES. For context: these files populate $_FILES via an html form with two browse buttons - one for each file to upload - and one submit button. The following output was produced with
    <pre><?php print_r($_FILES);?></pre>
    . Any help is appreciated. Thanks.

    Array
    (
    [userfile1] => Array
    (
    [name] => Hay-Bales-LeoKenney.jpg
    [type] => image/jpeg
    [tmp_name] => C:\wamp\tmp\php441.tmp
    [error] => 0
    [size] => 356369
    )

    [userfile2] => Array
    (
    [name] => LK-Holding on.jpg
    [type] => image/jpeg
    [tmp_name] => C:\wamp\tmp\php442.tm
    [error] => 0
    [size] => 312401
    )

    )


    • Quote
     
    lkenn, Feb 12, 2013 IP
  2. innozemec

    innozemec Active Member

    Messages:
    84
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    68
    #2
    foreach($_FILES as $afile)
    {
    // now $afile holds each array so do whatever you need

    // sample..
    echo $afile['name'];
    }
     
    innozemec, Feb 12, 2013 IP