0

我从 plupload 得到了一个上传脚本,我想编辑一些东西,但我不知道怎么做。而不是只允许某些类型的文件,我只想限制一些扩展名,如 php,exe,cmd,bat 。

 var uploader = new plupload.Uploader({
     runtimes : 'html5,flash,silverlight', // Set runtimes, here it will use HTML5, if not supported will use flash, etc.
     browse_button : 'pickfiles', // The id on the select files button
     multi_selection: false, // Allow to select one file each time
     container : 'uploader', // The id of the upload form container
     max_file_size : '800kb', // Maximum file size allowed
     url : 'upload.php', // The url to the upload.php file
     flash_swf_url : 'js/plupload.flash.swf', // The url to thye flash file
     silverlight_xap_url : 'js/plupload.silverlight.xap', // The url to the silverlight file
     filters : [ {extensions : "zip,rar,jpg,gif,png,jpeg,"} ] // Filter the files that will be showed on the select files window
});

我想将过滤器更改为限制。任何人都可以帮助我吗?

@Luan,我找到了解决方案

if( invalidExtensions.indexOf(extension) >= 0 ){


      alert("the extension " + extension + " is invalid!");
      up.removeFile( files[i] );
      location.reload();

   }

谢谢

4

1 回答 1

0

您可以测试扩展名是否无效并删除文件...

var uploader = new plupload.Uploader({
     runtimes : 'html5,flash,silverlight', // Set runtimes, here it will use HTML5, if not supported will use flash, etc.
     browse_button : 'pickfiles', // The id on the select files button
     multi_selection: false, // Allow to select one file each time
     container : 'uploader', // The id of the upload form container
     max_file_size : '800kb', // Maximum file size allowed
     url : 'upload.php', // The url to the upload.php file
     flash_swf_url : 'js/plupload.flash.swf', // The url to thye flash file
     silverlight_xap_url : 'js/plupload.silverlight.xap', // The url to the silverlight file
     filters : [ {extensions : "zip,rar,jpg,gif,png,jpeg,"} ] // Filter the files that will be showed on the select files window
});

var invalidExtensions = [".php",".exe",".cmd",".bat" ];
var extension;

uploader.bind('FilesAdded', function(up, files) {

   for(var i = 0; i < files.length; i++){

       extension  = files[i].name.substr(-4).toLowerCase();

       if( invalidExtensions.indexOf(extension) >= 0 ){

          alert("the extension " + extension + " is invalid!");
          up.removeFile( files[i] );

       }

   }

});

我认为会奏效。

于 2013-08-30T00:28:03.390 回答