jQuery jquery文件上传限制文件数量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16011200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:11:22  来源:igfitidea点击:

jquery file upload restricting number of files

jqueryjquery-file-upload

提问by Uahmed

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

我正在使用 jquery 文件上传将文件上传到服务器。我想限制用户最多上传 6 个文件。我搜索了 wiki jquery 文件上传,但没有找到它的参数。有什么方法可以限制用户上传的数量

回答by Mohamed Ali

Use maxNumberOfFileshere is documentation:

maxNumberOfFiles这里使用的是文档

$('#fileuploadbasic').fileupload({

maxNumberOfFiles: 6

});

回答by Muhammad Tahir

maxNumberOfFileswas not working for me so i did the following

maxNumberOfFiles对我不起作用所以我做了以下

$('#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,
});

回答by Hemantha

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.

您可以通过“Uploadhandler.php”文件限制上传文件。更改“max_number_of_files”选项。为我工作。但它仅在您上传文件时进行验证。

回答by TheCodeLord

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

如果您使用的是“Krajee”文件上传,则必须使用

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

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

如果设置为 0,则表示允许的大小不受限制。默认为 0。

回答by Artipixel

You can try:

你可以试试:

$('#fileuploadbasic').fileupload({
  //.....
  paramName: 'your_input_name',
  add : function (e, data) {
    if(data.paramName != undefined) data.submit();
  }
});