plupload-中选定的文件数量限制

这是代码的一部分:

inprogress = false;
function getid(id) {
 return document.getElementById(id); 
}
var uploader = new plupload.Uploader({
 runtimes : 'gears,html5,flash,silverlight,browserplus',
 browse_button : 'link-browse',
 max_file_size : '100mb',
 url : 'site/upload/process.php?dir=<?php echo $uplid; ?>',
 flash_swf_url : 'site/upload/plupload.flash.swf',
 silverlight_xap_url : 'site/upload/plupload.silverlight.xap',
});
uploader.bind('Init', function(up, params) {
 //$('filelist').innerHTML = "<div>Current runtime: " + params.runtime + "</div>";
});
uploader.bind('FilesAdded', function(up, files) {
 if(uploader.files.length <= 0){
  var element = document.getElementById('standby');
  element.parentNode.removeChild(element);
 }
 if(up.files.length > 4 || uploader.files.length > 4)
 {
  alert('Only 5 files per upload !');
  return false;
 }
 for (var i in files) {
  getid('filelist').innerHTML += '<div class="item" id="' + files[i].id + '"><div class="name">' + files[i].name + '</div><div onclick="removeme(\''+files[i].id+'\')" id="remove-'+files[i].id+'" class="remove"></div><div class="size">[ ' + plupload.formatSize(files[i].size) + ' ]</div><div class="percent"></div></div>';
 }
});
uploader.bind('UploadFile', function(up, file) {
 getid('submit-form').innerHTML += '<input type="hidden" name="file-' + file.id + '" value="' + file.name + '" />';
});
uploader.bind('UploadProgress', function(up, file) {
 getid(file.id).getElementsByTagName('div')[3].innerHTML = '<span>' + file.percent + "%</span>";
});
uploader.bind('StateChanged', function(uploader) {
  if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
   window.location = "./dl/<?php echo $uplid; ?>"
  }
 });
getid('link-upload').onclick = function() {
 if(uploader.files.length < 1){
  alert('Please select files first.');
  return false;
 }
 inprogress = true;
 uploader.start();
 return false;
};
uploader.init();
function removeme(id){
 if(inprogress) return false;
 if(uploader.files.length == 1)
 getid('filelist').innerHTML += '<div id="standby"></div>';
 var element = document.getElementById(id);
 element.parentNode.removeChild(element);
 var toremove = '';
 for(var i in uploader.files){
  if(uploader.files[i].id === id){
   toremove = i;
  }
 }
 uploader.files.splice(toremove, 1);
}

我可以限制被上传的文件, 如果我有选择的4个文件,我选择5个以上->它会显示错误 但如果我在优先次选择,例如14个文件,它们将显示在“文件列表”来。 如何限制,或者把“返回false”; 感谢您的帮助:)
本文地址 :CodeGo.net/354057/ 
------------------------------------------------------------------------------------------------------------------------- 
1. 扩大if(up.files.length > 4 || uploader.files.length > 4)if(up.files.length > 4 || uploader.files.length > 4 || files.length > 4)。 
2. max_file_count:4选项来限制上传文件的数量 
3. 在回答罗布W公司的答案,upuploader是因为它是上传者的实例,因此,冗余,以及它会同时检查(uploader.files.length + files.length) > 4为了检查是否有几个文件,将采取已经“注册”文件到帐户时超过4(例如增加了2个文件,然后3档后)。 所以我会

if(uploader.files.length > 4 || files.length > 4 || (uploader.files.length + files.length) > 4) {


4. - Working for Pupload v2.0

$("#uploader").pluploadQueue({
 runtimes: 'html5,html4',
 url: 'upload.php',
 max_file_size: '2mb',
 unique_names: false,
 rename: true,
 prevent_duplicates: true,
 init : {
  FilesAdded: function(up, files) {
   var max_files = 12;
   plupload.each(files, function(file) {
   if (up.files.length > max_files) {
    alert('You are allowed to add only ' + max_files + ' files.');
    up.removeFile(file);
   }
   });
   if (up.files.length >= max_files) {
   $('#pickfiles').hide('slow');
   }
  },
  FilesRemoved: function(up, files) {
   if (up.files.length < max_files) {
   $('#pickfiles').fadeIn('slow');
   }
  }
  },
 resize : {width : 700, height : 700, quality : 90},
 filters: [
  {
   title: "Image files",
   extensions: "jpg,jpeg,gif,png"
  }
 ]
});



本文标题 :plupload-中选定的文件数量限制
本文地址 :CodeGo.net/354057/ 


转载于:https://my.oschina.net/u/2423641/blog/484010

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值