【问题标题】:Uploadifive - allowed file types like uploadiftyUploadifive - 允许的文件类型,例如 uploadifty
【发布时间】:2013-12-19 18:02:45
【问题描述】:

使用 uploadify 我可以设置允许的文件类型,例如

'fileType' : '*.jpg;*.gif;*.png;*.jpeg;',

它会显示在对话框中All files(*.jpg;*.gif;*.png;*.jpeg;)

uploadifive 中是否有让它完全像这样工作,我使用了我在论坛中找到的各种选项,我得到的最接近的是来自这个 thread 代码如下:

'fileType'  : ["image\/gif","image\/jpeg","image\/png","image\/jpg", "application\/pdf"],',


var accept_types = '';
if(typeof settings.fileType !== 'object'){
  settings.fileType = [settings.fileType];
}
for (var i=0;i<settings.fileType.length;i++){
   var filetype_match = /^([a-z0-9]+)$/g.exec(settings.fileType[i]);
     if(filetype_match != null){
         accept_types += filetype_match[1]+'/*,';
    }else{
         accept_types += settings.fileType[i]+',';
    }
}
accept_types = accept_types.slice(0,accept_types.length-1);
if(accept_types.length > 0){
   input.attr('accept', accept_types);
}                   


 // Check the filetype
                if (settings.fileType) {
                    if ($.isArray(settings.fileType)) {
                        var isValidFileType = 0;
                        for (var n = 0; n < settings.fileType.length; n++) {
                            if (file.type.indexOf(settings.fileType[n]) > -1) {
                                alert(isValidFileType + 'valid file');
                                isValidFileType = 1;
                            }
                        }
                        if (!isValidFileType) {
                            alert(isValidFileType + 'not validid');
                            alert(settings.fileType);
                            $data.error('FORBIDDEN_FILE_TYPE', file);

                        }
                    } else {
                        if (file.type.indexOf(settings.fileType) < 0) {

                            $data.error('FORBIDDEN_FILE_TYPE', file);
                        }
                    }
                }

这很好用,但是默认情况下它仍然显示“所有文件(.)”作为默认值,并可以从下拉列表中选择允许的文件。

理想情况下,我希望它看起来像“所有支持的文件类型(.pdf、.jpeg)”等作为默认显示

我不喜欢被禁止的文件类型使用的功能,因为我希望我的用户看到他们可以上传哪些文件,而不是仅仅为了它说被禁止的文件等而赌一把

谢谢

【问题讨论】:

    标签: jquery uploadify


    【解决方案1】:

    有 fileDesc 参数,您可以在其中提供自定义文本

    $('#fileInput').uploadify({

    'fileDesc': '所有支持的文件类型(.pdf、.jpeg)',

    });

    如果这个答案有帮助,别忘了标记为答案

    谢谢 乙

    【讨论】:

    • 您好,抱歉 AB,似乎其他用户编辑了我的帖子并将所有说 uploadifive 的内容更改为 uploadfiy.....我需要有关 uploadifive (HTML5) 而不是 Uploadify (flash) 的帮助 我没有足够的使用标签uploadifive发布的代表得分,但是您的帖子是正确的,但这不是我所追求的,因为这只会更改实际的文本和内容但是我需要允许的文件类型的功能,例如uploadify用于uploadifive,因为它确实不同的事情
    【解决方案2】:

    你要上传的Filetype应该在uploadifive.php文件中设置,它是一个数组,你可以这样设置:

     //Set the allowed file extensions
     $fileTypes = array('jpg', 'jpeg', 'gif', 'png', 'pdf', 'rar', 'zip');
    

    并且在demo页面你也可以设置你希望用户上传的fileType,就这样:

    <script type="text/javascript">
        <?php $timestamp = time();?>
        $(function() {
          $('#imageFile_new').uploadifive({
            'auto'             : false,
            'fileType'         : new Array("image","application"),
            'truncateLength'   : '15',
            'checkScript'      : '/check-exists.php',
            'formData'         : {
                                    'timestamp' : '<?php echo $timestamp;?>',
                                    'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
                                  },
             'queueID'          : 'drop_zone',
             'uploadScript'     : '/uploadifive.php',
             'onUploadComplete' : function(file, data) { console.log(data); }
           });
        });
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-26
      • 2018-02-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-04
      • 2013-05-23
      • 1970-01-01
      相关资源
      最近更新 更多