javascript jquery 多文件上传限制文件数量不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21347805/
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
jquery multiple file upload limit number of files not working
提问by Nish
Jquery multiple file upload with ajax.
Jquery 使用 ajax 上传多个文件。
option : {
limitMultiFileUploads : 3
}
is not working for jquery file upload.
不适用于 jquery 文件上传。
This is what i did :
这就是我所做的:
$(function() {
$('#attachUpload').fileupload({
dataType: 'json',
limitConcurrentUploads: 1,
option:
{
maxFileSize: 40000,
maxNumberOfFiles: 2
},
start: function(e) {
$('.btn-sent').unbind('click'); // important - remove all event handlers
},
done: function(e, data) {
var data = $.parseJSON(data._response.jqXHR.responseText);
doneflag--;
if (doneflag == 0) {
$('#frmCompose').submit();
}
},
submit: function(e, data) {
data.formData = setFormData();
},
add: function(e, data) {
}
});
but filesize limit and number of files limit not working can anyone help please.
但是文件大小限制和文件数量限制不起作用任何人都可以帮忙。
回答by Adil Malik
You are actually looking for maxNumberOfFilesoption.
您实际上是在寻找maxNumberOfFiles选项。
More details on the doc: https://github.com/blueimp/jQuery-File-Upload/wiki/Options
有关文档的更多详细信息:https: //github.com/blueimp/jQuery-File-Upload/wiki/Options
My working code:
我的工作代码:
$('#fileupload').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: '../uploaderDemo/server/php/',
maxNumberOfFiles: 1,
acceptFileTypes: /(\.|\/)(mp3|wav)$/i
});
回答by Kevin Heidt
Get rid of the object with the name "option" and put the two settings at the same level as the rest of the options.
去掉名称为“选项”的对象,并将这两个设置与其余选项放在同一级别。
$(function() {
$('#attachUpload').fileupload({
dataType: 'json',
limitConcurrentUploads: 1,
maxFileSize: 40000,
maxNumberOfFiles: 2,
start: function(e) {
$('.btn-sent').unbind('click'); // important - remove all event handlers
},
done: function(e, data) {
var data = $.parseJSON(data._response.jqXHR.responseText);
doneflag--;
if (doneflag == 0) {
$('#frmCompose').submit();
}
},
submit: function(e, data) {
data.formData = setFormData();
},
add: function(e, data) {
}
});

