2

我尝试了许多不同的建议,包括uploadify论坛上的建议:http ://www.uploadify.com/forum/#/discussion/8232/upload-five-html-5-file-type-filter-capability/ p1

但是这些似乎并没有限制用户更改文件类型。有任何想法吗?这是我下面的代码:

<script type="text/javascript">

<?php $timestamp = time();?>

$(function() {

    if ($('#fileupload').length > 0) {    

      $('#fileupload').uploadifive({

        'auto'             : true,
        'checkScript'      : '../home/assets/uploadifive/check-exists.php',
        'formData'         : {
                     'timestamp' : '<?php echo $timestamp;?>',
                     'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
                             },
        //'queueID'          : 'queue',
        'uploadScript'     : '../home/assets/uploadifive/uploadifive.php',
        'multi'    : false,
        'removeCompleted' : false,
          'fileSizeLimit' : '3MB',
          'uploadLimit'  : 1,
          'buttonText':'Select File',
           onSelect: function() {
               $('#btn_submit').attr({disabled: true, value:'Uploading...' }).css( "background-color", "#707070" );
               },
           onUploadComplete: function(file,data,reponse) {
               $('#uploadedfile').val(data);
                 $("#btn_submit").attr({disabled: false, value:'Register' }).css( "background-color", "#D4D0C8" );
                 alert('The file ' + file.name + ' was successfully uploaded ');
        },

       // 'fileType'     : 'application/pdf|application/doc|application/docx'     //not 
                                                                                 //working.
       // 'fileType'     : ["gif","jpeg","png"]   //not working.
       // 'fileType'     : 'image/png|image/jpg' //not working.
       // 'fileType'     : 'image/*'    // works but does not restrict user from changing 
                                        // it something else.
       // 'fileType': ["image\/jpeg","image\/png"]  // works but does not restrict user   
                                                    // from changing it something else.       
      });

    }

});

</script>
4

2 回答 2

1

这里同样的问题。我已经更改了'fileType':'image',它允许整个img文件但不允许其他文件(抛出禁止的文件类型错误)并且在我的Php中我添加了$fileTypes = array('jpg','jpeg',' gif', 'png'); 允许的文件扩展名 所以我们只能过滤 jpg gif 和 png 文件。但它会增加上传的文件计数uploadify。

于 2014-12-04T06:44:43.887 回答
1

我在一个线程上找到了这个答案,但它适用于 v 1.0。* 我不确定他们是否已经为 1.2.2 修复了它 在第 283 行更改源 JS (jquery.uploadifive-v1.0.js) 以使其正常工作并接受我的文件类型数组。

var v = 0;
                            for (var n = 0; n < settings.fileType.length; n++) {
                                if (file.type.indexOf(settings.fileType[n]) > -1) {
                                    v += 1;
                                }
                            }
                            if (v < 1) {
                                $data.error('FORBIDDEN_FILE_TYPE', file);
                            }

我试过传递数组以及 | 分离的文件扩展名仍然无法正常工作。

于 2016-11-21T16:16:13.657 回答