jquery multiple file upload limit number of files not working

匿名 (未验证) 提交于 2019-12-03 00:52:01

问题:

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) {                 }     }); 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!