dttphb59319 2017-07-18 17: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 17: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条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭