Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

how to count number of uploaded files in 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>

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";
    }
} 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...