我使用Plupload 1.5.6将图像上传到服务器但是我想限制允许的文件数量为6.我在这里尝试了一些建议并通过谷歌搜索,但它们仍然允许我上传尽我所能。我的代码是:
var maxfiles = 6;
$(function() {
$("#uploader").pluploadQueue({
runtimes : 'html5,silverlight,flash,gears,browserplus',
url : 'upload.php',
max_file_size : '2mb',
chunk_size : '1mb',
unique_names : false,
max_file_count: maxfiles,
resize : {width : 700, height : 700, quality : 90},
filters : [
{title : "Image files", extensions : "jpg,gif,png"}
],
flash_swf_url : '/js/plupload.flash.swf',
silverlight_xap_url : '/js/plupload.silverlight.xap',
preinit: attachCallbacks,
init : {
FilesAdded: function(up, files) {
plupload.each(files, function(file) {
if (up.files.length > maxfiles) {
up.removeFile(file);
}
var upa = $('#uploader').plupload('getUploader');
var i = 0;
while (i<=upa.files.length) {
ultimo = upa.files.length;
if (ultimo > 1) {
if (i > 0) {
ultimo2 = ultimo - 1;
ii = i-1;
if (ultimo2 != ii) {
if (up.files[ultimo - 1].name == upa.files[i-1].name) {
up.removeFile(file);
}
}
}
}
i++;
}
});
if (up.files.length >= maxfiles) {
$('#uploader_browse').hide("slow");
}
},
FilesRemoved: function(up, files) {
if (up.files.length < maxfiles) {
$('#uploader_browse').fadeIn("slow");
}
}
}
});
$('form').submit(function(e) {
var uploader = $('#uploader').pluploadQueue();
if (uploader.files.length > 0) {
uploader.bind('StateChanged', function() {
if(uploader.files.length === (uploader.total.uploaded + uploader.total.failed)){
$('form')[0].submit();
}
});
uploader.start();
} else {
alert('You must queue at least one file.');
}
return false;
});
});
我尝试将其更改为plupload而不是pluploadQueue,但这并不起作用。