如何计算PHP中上传文件的数量 [英] how to count number of uploaded files in php

查看:264
本文介绍了如何计算PHP中上传文件的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何计算上传文件的数量?
这是我的表单:

How can i count the number of uploaded files? This is my form:

<div id="dragAndDropFiles" class="uploadArea">
        <h1>Drop Images Here</h1>
    </div>
    <form id="sfmFiler" class="sfmform" method="post" enctype="multipart/form-data">
        <input type="file" name="file" id="file" multiple />
        <input type="submit" name="submitHandler" id="submitHandler" class="buttonUpload" value="Upload">
    </form>

这是上传文件的php片段:

and this is the piece of php which uploads the files:

if($_SERVER['REQUEST_METHOD'] == "POST") {
    $tmpFilePath = $_FILES['file']['tmp_name'];
    $newFilePath = $dir.'/' . $_FILES['file']['name'];
    if(move_uploaded_file($tmpFilePath, $newFilePath)) {
      echo "xxx files are successfully uploaded";
    }
} 


推荐答案

在这段代码只得到一个文件,这就是为什么要得到计数结果1.如果更改输入文件名,例如 file []

In this code you are getting only one file thats why you are getting count result 1. if change your input file name like "file[]"

  <input type="file" name="file[]" id="file" multiple />

,然后使用下面的行代码,您将获得想要的结果。导致需要数组来保存输入数据。

and then use the below line code you will get your desire result. Cause its needs an array filed to hold the input data.

 <?php echo count($_FILES['file']['name']); ?>

谢谢,我尝试在系统中获取结果。

Thanks, i tried in my system get the result.

这篇关于如何计算PHP中上传文件的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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