我怎样才能知道一些上传的文件与PHP? [英] How can I know a number of uploaded files with PHP?

查看:182
本文介绍了我怎样才能知道一些上传的文件与PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

我怎样才能知道一些上传的文件与PHP?

你好,我有一个三个表格

pre $输入类型=文件

标记。 在服务器端如何知道用户上传文件的数量?他可以上传3个文件,也可以是2个文件,1甚至什么都不是。我需要知道用户上传了多少文件。



如果我使用代码

  echo count($ _ FILES); 

它将始终显示值3.因为表单包含三个文件字段。如果用户只上传两个文件,代码将显示3,但是正确的值是2.

试试 p>

  $ count = 0; 
foreach($ _ FILES as $ file){
if($ file [size]>'0')$ count ++;
}


Possible Duplicate:
How can I know a number of uploaded files with PHP?

Hello, I have a form with three

input type="file"

tags. How can I know on the server side amount of files uploaded by the user? He can upload 3 files, or may be 2 files, 1 or even nothing. I need to know how much files user have uploaded.

If I use the code

echo count($_FILES);

It will always display the value of 3. Because form contains three file fields. If the user will upload only two files, the code will display 3, but the right value is 2.

解决方案

try

$count=0;
foreach($_FILES as $file){
if ($file["size"]>'0')$count++;
}

这篇关于我怎样才能知道一些上传的文件与PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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