2014-01-25 55 views
4

jquery使用ajax多文件上傳。jquery多文件上傳限制文件數量不能正常工作

option : { 
    limitMultiFileUploads : 3  
} 

不適用於jquery文件上傳。

這是我做過什麼:

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

但大小限制和文件數量限制不工作誰能幫助請。

+0

觀察到的行爲是什麼? – Fractaliste

+0

上的提交文件正在上傳,但文件限制超出時不應上傳文件。 – Nish

+0

你想做什麼?同時上傳2個限制或每個會話上傳2個? – Fractaliste

回答

2

您實際上正在尋找maxNumberOfFiles選項。

的文檔的更多細節:https://github.com/blueimp/jQuery-File-Upload/wiki/Options

我的工作代碼:

$('#fileupload').fileupload({ 
     // Uncomment the following to send cross-domain cookies: 
     //xhrFields: {withCredentials: true}, 
     url: '../uploaderDemo/server/php/', 
     maxNumberOfFiles: 1, 
     acceptFileTypes: /(\.|\/)(mp3|wav)$/i 
    }); 
0

擺脫名爲「選項」的對象,並將這兩個設置在同一水平的其他選項。

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