我遇到问题,我正在通过uploadfile js创建一个函数上传。如果文件不是excel文件,系统将显示错误。如何通过uploadfile js实现验证excel格式?这是我的来源
$(document).ready(function() {
var uploadObj = $("#fileuploader").uploadFile({
url:"php/upload.php",
fileName:"myfile",
uploadStr: "Nhập file upload",
abortStr:"Hủy bỏ",
uploadErrorStr:"Lỗi khi upload, vui lòng kiểm tra lại",
sizeErrorStr:"Dung lượng file vượt quá giới hạn",
autoSubmit:false
});
});
答案 0 :(得分:0)
您是否尝试过allowedTypes:' xls,xslx' ?
你也可以尝试onSelect回调:
onSelect: function(files) {
if (files[0].type != 'application/vnd.ms-excel') {
throw new Error('Not excel file');
}
}
答案 1 :(得分:0)
这将对您有所帮助:
$("#fileuploader").change(function () {
var ext = $(this).val().split('.').pop();
if (ext != 'give extension here') {
alert("Please valid file type");
return false;
}
});