donglin6313 2013-08-23 02:56
浏览 72
已采纳

如何循环$ _FILES?

I want to add loop around $_FILES[] array. I tried $count= count($_FILES['files'][name]) and then add loop around it for($i=0; $i<=$count; $i++), but it is not giving me desired output.

I want add to loop only from the files that the User is uploading, Right now it is counting all of the 'files' available in the form.

Kindly tell me a way to count only the uploaded files and loop through them.

  • 写回答

4条回答 默认 最新

  • dongzhihong3940 2013-08-23 03:03
    关注

    Loop ever the $_FILES array and use the ['name'] inside the iteration:

    $count = count($_FILES['files'])
    for($i=0; $i<=$count; $i++) {
      if ($_FILES['files'][$i]['size'])
        echo $_FILES['files'][$i]['name']."
    ";
    }
    

    Even easier is to use a foreach loop:

    foreach($_FILES['files'] as $file) {
      if($file['size'])
        echo $file['name']."
    ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部