2013-05-23 5 views
7

मैं jQuery फ़ाइल अपलोड का उपयोग कर रहा हूं और maxNumberOfFiles को 1 पर सेट कर रहा हूं। हालांकि, यह एक समय में एक से अधिक फाइलों को अनुमति दे रहा है। दस्तावेज कहता है ...jQuery फ़ाइल अपलोड maxNumberOfFiles और getNumberOfFiles विकल्प

The maxNumberOfFiles option depends on the getNumberOfFiles option, which is defined by the UI and AngularJS implementations. 

इस विषय पर कोई और दस्तावेज नहीं है। getNumberOfFiles सिर्फ एक समारोह आप में पारित कर सकते हैं है।

यहाँ मैं क्या है ...

$('#fileupload').fileupload({ 
       maxNumberOfFiles: 1, 
       getNumberOfFiles: function() { return 1 } 
}); 

किसी maxNumberOfFiles विकल्प काम है?

उत्तर

11

मेरा मानना ​​है कि getNumberOfFiles jquery.fileupload-ui.js (8.2.1) के केवल added as an option to a recent version था।

वैकल्पिक रूप से, आप विकल्प singleFileUploads से false पर सेट कर सकते हैं, और add कॉलबैक में यदि आप एक से अधिक फ़ाइल जोड़ते हैं तो आप त्रुटियों को फेंक सकते हैं।

var maxFiles = 1; 
$('#fileupload').fileupload({ 
    singleFileUploads: false, 
    url: '/uploadUrl' 
}).bind('fileuploadadd', function (e, data) { 
     var fileCount = data.files.length; 
     if (fileCount > maxFiles) { 
      alert("The max number of files is "+maxFiles); 
      return false; 
     } 
    }); 
1

मैं बस एक साधारण काउंटर काम करता है अच्छी तरह से

var maxFiles = 1; 
var counter=0; 
$('#fileupload').fileupload({ 
url: '/uploadUrl', 
add: function (e, data) { 
     if(counter < maxFiles){ 
      counter++; 
    }else return false; 

    } 
}); 
का उपयोग कर पाया
संबंधित मुद्दे