问题
Jquery multiple file upload with ajax.
option : {
limitMultiFileUploads : 3
}
is not working for jquery file upload.
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.
回答1:
You are actually looking for maxNumberOfFiles
option.
More details on the doc: 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
});
回答2:
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) {
}
});
来源:https://stackoverflow.com/questions/21347805/jquery-multiple-file-upload-limit-number-of-files-not-working