2017-03-08 5 views
0

basic version of jQuery-File-Upload을 사용하고 입력 유효성을 검사하고 싶습니다. 크기에 제약이있는 특정 유형 만 업로드하려고합니다.jQuery 파일 업로드 : 기본 버전으로 확인

그래서 acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, 옵션을 적용하면 이미지 만 업로드 할 수 있다고 생각합니다. 놀랍게도 acceptFileTypes 옵션이 무시되며 파일을 업로드 할 수 있습니다 (예 : test.tar).

기본 버전으로 입력을 확인할 수 있습니까? 다음은 변경된 코드입니다 (기본 예제에는 acceptFileTypesmaxFileSize 만 추가했습니다).

$(function() { 
    'use strict'; 
    // Change this to the location of your server-side upload handler: 
    var url = 'server/php/'; 
    $('#fileupload').fileupload({ 
     url: url, 
     dataType: 'json', 
     acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, 
     maxFileSize: 999000, 
     done: function (e, data) { 
      $.each(data.result.files, function (index, file) { 
       $('<p/>').text(file.name).appendTo('#files'); 
      }); 
     }, 
     progressall: function (e, data) { 
      var progress = parseInt(data.loaded/data.total * 100, 10); 
      $('#progress .progress-bar').css(
       'width', 
       progress + '%' 
      ); 
     } 
    }).prop('disabled', !$.support.fileInput) 
     .parent().addClass($.support.fileInput ? undefined : 'disabled'); 
}); 

답변

0

캐시를 지운 후에도 스크립트가 변경 사항을 허용하는 것 같습니다. 이제 유효성 검사가 작동합니다.