Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to count number of uploaded files in php

Tags:

php

count

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";
    }
} 
like image 476
Jack Maessen Avatar asked Nov 28 '22 14:11

Jack Maessen


1 Answers

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.

like image 69
Asif Uddin Avatar answered Dec 06 '22 00:12

Asif Uddin