Search code examples
javascriptjqueryfile-uploadjquery-file-upload

Limit number files in jQuery-File-Upload


I use plugin jQuery-File-Upload. How can I to limit of number selecting files from local machine?

https://github.com/blueimp/jQuery-File-Upload/wiki/Options


Solution

  • You can limit the number of files before submitting by adding a onchange event to the input element. As soon as it's triggered you check the number of files. Here is a simple example for a 2 file limit:

    <input type="file" onchange="if(parseInt($(this).get(0).files.length)>2) 
                                   alert('You can only upload a maximum of 2 files'); 
                                 else alert('You are within the limit');" multiple/>
    

    See demo on fiddle here