0
我有以下代碼,使用dropzonejs上傳excel表單,但最大文件數爲1,只接受excel類型... 當多個文件上傳到正確的文件類型時,首先啓動錯誤,並由alert('please enter correct file format')
生成消息,然後僅通過alert('You cannot upload more then 1 file at a time.')
提醒真實錯誤消息。所以,我的問題是如何顯示真正的錯誤消息時初始化錯誤...在dropzone檢查文件類型
<script>
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);
}
});
}
});
</script>
工作就像一個魅力....謝謝你的回答 –
我想你不會遇到任何問題與IE11呢?我目前面臨的問題是type只是一個空字符串,但我在其他瀏覽器中沒有這樣的問題。在這方面努力尋找網上的任何東西。謝謝! –
我剛剛在他們的Github上發現了一些東西,其實只是爲了將來的參考,任何人都需要它https://github.com/enyo/dropzone/issues/1143 –