jquery file upload restricting number of files

廉价感情. 提交于 2019-11-27 22:50:46

Use maxNumberOfFiles here is documentation :

$('#fileuploadbasic').fileupload({

maxNumberOfFiles: 6

});

maxNumberOfFiles was not working for me so i did the following

$('#fileuploadbasic').fileupload({
    change : function (e, data) {
        if(data.files.length>=5){
            alert("Max 5 files are allowed")
            return false;
        }
    },
    maxFileSize: 20000000,
    acceptFileTypes: /(\.|\/)(jpe?g|png)$/i,
});

You can limit the uploading files by the "Uploadhandler.php" file .change the "max_number_of_files" option. works for me. But it only validates when you upload the file.

If you are using the "Krajee" fileupload, then you will have to use

$('#fileuploadbasic').fileinput({
    maxFileCount: 6
});

If set to 0, it means size allowed is unlimited. Defaults to 0.

You can try:

$('#fileuploadbasic').fileupload({
  //.....
  paramName: 'your_input_name',
  add : function (e, data) {
    if(data.paramName != undefined) data.submit();
  }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!