How can I know a number of uploaded files with PHP?(我如何知道使用 PHP 上传的文件数量?)
问题描述
我有一个表格,里面有几个
I have a form with several
input type="file"
标签.我如何在服务器端知道用户上传的文件数量.他可以上传3个文件,或者可能是5个文件,1个甚至什么都没有.我需要知道用户上传了多少文件.
tags. How can I know on the server side amount of files uploaded by the user. He can upload 3 files, or may be 5 files, 1 or even nothing. I need to know how much files user have uploaded.
推荐答案
如果您输入的上传标签名称为 file1
, file2
则
If you are having input upload tags with name like file1
, file2
then
if($_FILES['file1']['size'] > 0)
echo "User uploaded some file for the input named file1"
现在对于许多文件(查看您的输出),像这样运行 foreach 循环:-
Now for many files (looking at the output you are having), run a foreach loop like this:-
$cnt=0;
foreach($_FILES as $eachFile)
{
if($eachFile['size'] > 0)
$cnt++;
}
echo $cnt." files uploaded";
我不确定为什么 我如何知道使用 PHP 上传的文件数量? 被否决了?对于'0'?
I am not sure why the similar answer in How can I know a number of uploaded files with PHP? got downvoted? For the '0' ?
这篇关于我如何知道使用 PHP 上传的文件数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我如何知道使用 PHP 上传的文件数量?


- SoapClient 设置自定义 HTTP Header 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Laravel 仓库 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01