0

With uploadify I could set the allowed file types like

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

and it would display in the dialog box All files(*.jpg;*.gif;*.png;*.jpeg;)

Is there anyway in uploadifive to get it to work exactly like this, I have used various options that I have found in the forum and the closest I have got is from this thread code below:

'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);
                        }
                    }
                }

This works great, however by default it still displays "All files(.)" as default with the option to select the allowed files from the drop down.

ideally I would like it to look something like "All supported files types (.pdf, .jpeg)" etc to appear as the default

I do not like the functionality that the forbidden file types uses as I want my users to see what files they can upload and not gamble on a click only for it to say forbidden file etc

Thanks

Lee

4

2 回答 2

0

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

$('#fileInput').uploadify({

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

});

如果这个答案有帮助。不要忘记标记为答案

谢谢 AB

于 2013-06-27T09:30:27.093 回答
0

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

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

演示页面,您还可以设置您希望用户上传的文件类型,只需这样做:

<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>
于 2013-12-19T10:02:45.603 回答