I use Plupload 1.5.6 to upload images to the server, but I would like to limit the number of files allowed to 6. I tried several suggestions here and through a Google search, but all of them still let me upload as much as I want. My code is:
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; }); });
I tried changing it only to plupload instead of pluploadQueue, but this does not work.
source share