Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript, count how many files were attached to a file upload input

I have this file input:

<input type="file" name="photo[]" multiple="yes">

What I want is, when someone uploads a file/files to it, I want to alert them how many files were uploaded (altogether). Like if I upload 3 files, it will alert "3 files were uploaded". And if I add 2 more files it will alert "5 files were uploaded" (adding the 2 files uploaded before).

like image 629
Paranoid Avatar asked Dec 07 '13 07:12

Paranoid


1 Answers

Try this code:

var numFiles = $("input:file")[0].files.length;
like image 174
zord Avatar answered Sep 24 '22 18:09

zord