jquery file upload restricting number of files

2020-02-01 01:03发布

I am using jquery file upload to upload the files to the server . I want to restrict the user to upload maximum 6 files . I search the wiki jquery file upload but didnt find the parameter for it . Is there any way that i can restrict the user on number of uplaods

5条回答
萌系小妹纸
2楼-- · 2020-02-01 01:38

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.

查看更多
神经病院院长
3楼-- · 2020-02-01 01:41

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.

查看更多
孤傲高冷的网名
4楼-- · 2020-02-01 01:46

You can try:

$('#fileuploadbasic').fileupload({
  //.....
  paramName: 'your_input_name',
  add : function (e, data) {
    if(data.paramName != undefined) data.submit();
  }
});
查看更多
做自己的国王
5楼-- · 2020-02-01 01:53

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,
});
查看更多
smile是对你的礼貌
6楼-- · 2020-02-01 01:56

Use maxNumberOfFiles here is documentation :

$('#fileuploadbasic').fileupload({

maxNumberOfFiles: 6

});
查看更多
登录 后发表回答