파일 유효성 체크하는 방법
1. 전체적인 file type 제어
$('input[type="file"]').change(function () {
var ext = this.value.match(/\.(.+)$/)[1].toLowerCase();
switch (ext) {
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'war':
case 'zip':
case 'xlsx':
case 'docx':
case 'hwp':
$('#uploadButton').attr('disabled', false);
break;
default:
alert('지원하지 않는 형식입니다');
this.value = '';
}
});
2. 부분적인 file type 제어 (id 사용)
if( $("#file").val() != "" ){
var ext = $('#file').val().split('.').pop().toLowerCase();
if($.inArray(ext, ['gif','png','jpg','jpeg']) == -1) {
alert('gif,png,jpg,jpeg 파일만 업로드 할수 있습니다.');
return;
}
}
출처 : https://stackoverflow.com/questions/651700/how-to-have-jquery-restrict-file-types-on-upload
출처: http://beans9.tistory.com/165 [Beans9 : easy easy easy !!]