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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里