dttphb59319 2017-07-18 09:16
浏览 48
已采纳

获取PHP $ _FILES数组名称

I have a html form sending to php script with "post" method (no ajax involved).

In the form i have some type="file" fields.

Now in my php script i have a php foreach loop looping through the sent files:

foreach($_FILES as $file) {
// Some checks and actions.
}

In that loop i want to be able to use the current file array name (which is equal to the name attribute of the upload filled it was uploaded from of course), so i treid:

foreach($_FILES as $file) {
// Some checks and actions.
print ($file);
}

But that's just echoing "Array".

Important note: My $_FILES array is structured like that:

Array
(
    [_pf_photo1] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

    [_pf_photo2] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

    [_pf_photo3] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

    [_pf_photo4] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

    [_pf_photo5] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

    [selfimage] => Array
        (
            [name] => IMG_9785.JPG
            [type] => image/jpeg
            [tmp_name] => /tmp/phpWMOKhn
            [error] => 0
            [size] => 104221
        )

)

($_FILES can be structured another way, so to make things clear). so in that example what i want to get in the loop (for the array name part) is:

_pf_photo1, _pf_photo2, _pf_photo3, _pf_photo4, _pf_photo5, selfimage

展开全部

  • 写回答

2条回答 默认 最新

  • doufeng9567 2017-07-18 09:18
    关注

    This may be what you're looking for if I am understanding your problem correctly.

    foreach($_FILES as $key => $value) {
        echo $key;
    }
    

    The only other way I can understand this question is if you're incorrectly using print. To print an object/array out with all of its data you can use var_dump instead of print.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?