php多个文件上传获取用户上传的文件的确切数量,而不是数组中所有输入字段的数量 [英] php multiple file uploads get the exact count of files a user uploaded and not the count of all input fields in the array

查看:55
本文介绍了php多个文件上传获取用户上传的文件的确切数量,而不是数组中所有输入字段的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的.我放弃了.当使用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?

到目前为止,无论我做什么,都将返回表单中所有字段的计数以及用户上载的文件的计数.因此,如果表单中的总字段为3,而一个用户仅上传了2个文件,那么我仍然获得3作为上传文件的数量.

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.

一个地方建议使用array_filter来做到这一点,但这完全超出了我.

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

您遵循的任何故障安全方法都可以提出建议,而不是通过遍历FILES数组size进行检查吗?

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>

推荐答案

正像他们告诉您的那样,只需使用array_filter().

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

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

它将返回正确的数字

这篇关于php多个文件上传获取用户上传的文件的确切数量,而不是数组中所有输入字段的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆