【发布时间】:2016-11-17 03:45:56
【问题描述】:
我有以下代码使用 dropzone.js 在某些条件下上传 excel 表,例如最大文件数为 1,并且只接受 excel 类型...
当以正确的文件类型上传多个文件时,首先引发错误并由alert('please enter correct file format') 生成消息,然后只有真正的错误消息由alert('You cannot upload more then 1 file at a time.') 发出警报。所以,我的问题是如何在初始化错误时显示真正的错误消息...
var myDropzone = new Dropzone("div#myAwesomeDropzone", {
url: "<?php echo base_url(); ?>test/upload_excel_file",
maxFiles: 1,
acceptedFiles: ".xls,.xlsx",
dictDefaultMessage:
"Drag an excel sheet here to upload, or click to select one",
init: function () {
this.on("maxfilesexceeded", function (file) {
alert("You cannot upload more then 1 file at a time.");
this.removeFile(file);
});
this.on("error", function (file) {
var type = file.type;
//alert(type);
if (type != "application/vnd.ms-excel") {
alert("please enter correct file format");
this.removeFile(file);
} else if (
type !=
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
) {
alert("please enter correct file format");
this.removeFile(file);
}
});
},
});
【问题讨论】:
标签: javascript php jquery codeigniter dropzone.js