$('INPUT[type="file"]').change(function() {
var ext = this.value.match(/\.(.+)$/)[1];
var control = $("#uploaded_file");
switch (ext) {
case 'doc':
case 'docx':
case 'pdf':
case 'wps':
case 'rtf':
case 'txt':
case 'xps':
$('#uploadButton').attr('disabled', false);
break;
default:
alert('\'' + ext + '\' is not an allowed file type.\n\nPlease select the correct file type:\n\n\t.DOC, .DOCX, .PDF, .WPS, .RTF, .TXT, .XPS');
$('#uploadButton').attr('disabled', true);
control.replaceWith(control = control.val('').clone(true));
}
});
이제는 사용자가 ".TXT"가있는 파일을 선택하면 TXT가 txt와 같지 않으므로 예외 오류가 발생하므로 사용하려고 시도했습니다. strtolower 함수. 그러나 스크립트를 사용하면 스크립트 자체가 작동하지 않습니다.파일 jquery에서 파일 유형을 확인하십시오
이 작동하지 않습니다하여 strtolower와 스크립트를 수정 :
$('INPUT[type="file"]').change(function() {
var ext = this.value.match(/\.(.+)$/)[1];
var cext = strtolower(ext);
var control = $("#uploaded_file");
switch (cext) {
case 'doc':
case 'docx':
case 'pdf':
case 'wps':
case 'rtf':
case 'txt':
case 'xps':
$('#uploadButton').attr('disabled', false);
break;
default:
alert('\'' + cext + '\' is not an allowed file type.\n\nPlease select the correct file type:\n\n\t.DOC, .DOCX, .PDF, .WPS, .RTF, .TXT, .XPS');
$('#uploadButton').attr('disabled', true);
control.replaceWith(control = control.val('').clone(true));
}
});
어디 작동하지 않는 원인이되는 오류?
'하여 strtolower()을'PHP는 기능이 아닌 자바 스크립트 기능입니다. String.toLowerCase() (예 :'var ext = "TXT"; switch (ext.toLowerCase()) {...')를 찾고있다. –