我如何知道使用 PHP 上传的文件数量?

2022-01-09 00:00:00 upload 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' ?

相关文章