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条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站