UploadiFive 1.2.2 'fileType' filter capability/restriction does not work

2.1k Views Asked by At

I have tried a number of different suggestions including the suggestion on the uploadify forum: http://www.uploadify.com/forum/#/discussion/8232/upload-five-html-5-file-type-filter-capability/p1

But these do not seem to restrict the user from changing the file type. Any ideas? This is my code below:

<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>
2

There are 2 best solutions below

1
On

Same problem here. I've changed 'fileType' :'image', It allows whole img files but not other files (Throws forbidden file type error) and in my Php I've added $fileTypes = array('jpg', 'jpeg', 'gif', 'png'); Allowed file extensions So we can filter only jpg gif and png files. But it will increment uploaded file count uploadify.

0
On

I found this answer on a thread but its for v 1.0.* I am not sure they have fixed it for 1.2.2 yet Change the source JS (jquery.uploadifive-v1.0.js) at line 283 to get this to work and accept my array of fileType.

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

I have tried passing array as well as | separated file extension its still not working.