2016-07-14 14 views
0

ファイルの最大数が1で、Excelタイプのみが受け入れられるなど特定の条件でdropzonejsを使用してExcelシートをアップロードするには、次のコードがあります。 ファイルタイプが正しい場合は、エラーが最初に開始され、メッセージはalert('please enter correct file format')によって生成され、実際のエラーメッセージのみがalert('You cannot upload more then 1 file at a time.')によって警告されます。そう、私の質問は、文はあなたが明らかにエラーを与える2つの条件のいずれかに該当する場合は、誤ったファイルタイプのメッセージは、あなたとあなたのために起こる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> 

答えて

2

...エラーが初期化されるとき、実際のエラーメッセージを表示する方法であります。

ので、代わりにあなたが使用する必要があります。

switch(file.type) 
{ 
    case 'application/vnd.ms-excel': 
    case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 
    break; 
    default: 
    alert('please enter correct file format'); 
    break; 
} 
+0

は、私はあなたがすべてでIE11に問題を経験したと仮定していないあなたの答え –

+0

をありがとうございました....魅力のように働きましたか?私は現在、型が空の文字列であるという問題に直面していますが、他のブラウザではこのような問題はありません。これに関してもオンラインで何かを見つけようと苦労している。ありがとう! –

+0

私はちょうど誰かがそれを必要とするならば、実際に将来の参照のために、彼らのGithubで何かを見つけましたhttps://github.com/enyo/dropzone/issues/1143 –

関連する問題