6

我正在使用 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 但这不起作用。

4

0 回答 0