dongquweng5152 2014-08-21 10:26
浏览 125
已采纳

php多文件上传获取用户上传文件的确切数量,而不是数组中所有输入字段的数量

Ok. I give up on this. When uploading multiple files to the server using php, what is a fail safe method to return the count of files the user has actually uploaded?

Whatever I have done so far, returns the count of all the fields in the form, and the count of the files a user uploads. So if the total fields in the form were 3 and a user uploaded only 2 files, I still get 3 as the count of file uploaded.

One place suggested using array_filter to do this, but that's totally beyond me.

echo count($_FILES['file']['tmp_name']); //3

echo count($_FILES['file']); //3

Any fail safe method you follow and can suggest other than looping through the FILES array size to check for this?

My form is structured like any other:

<form action="process.php" method="post" enctype="multipart/form-data">
<div><input type="file" name="file[]"></div>
<div><input type="file" name="file[]"></div>
<div><input type="file" name="file[]"></div>
<div><input type="submit"></div>
</form>
  • 写回答

3条回答 默认 最新

  • douhu2370 2014-08-21 10:33
    关注

    Exactly as they told you, just simply use array_filter().

    echo count(array_filter($_FILES['file']['name']));
    

    It will return the right number

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

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功