2014-03-27 36 views
0

我将文件上传到文件上传控件后验证文件类型。在验证中,我允许.xls文件类型。但在某些浏览器中不允许.xls文件。文件上传控件在某些浏览器中不接受.xls文件?

可能是什么问题?

var fileExt = ["application/pdf","application/msword", "image/gif", "image/jpeg", 
       "image/png", "text/csv", "text/html", "application/vnd.ms-excel", 
       "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 
       "application/vnd.ms-powerpoint", "application/vnd.openxmlformats- 
         officedocument.presentationml.presentation", 
       "application/vnd.openxmlformats- 
         officedocument.wordprocessingml.document", "text/plain"]; 
if (fileExt.indexOf(file.type) <= -1) { 
    $('input[id="Attachment"]').removeClass("valid").addClass("input-validation-error"); 
    $('#spanAttachment').removeClass("field-validation-valid").addClass("input-validation-error red"); 
    $('#spanAttachment').empty(); 
    $('#spanAttachment').append("<span for='FirstName' 
          class=''>Filetype is not accepted.</span>"); 
    $('#btnSubmit').attr('disabled', true); 
} 

http://i.stack.imgur.om/CVQfL.png

+0

在这种情况下,我假设某些浏览器无法正确解析文件类型,并简单地发送默认的文件类型,而不是'application/vnd.ms-speadsheet'类型。在有问题的浏览器中提醒'file.type'以查看它实际返回的内容。 – Tommy

+0

@tommy,警报不显示任何内容。没有任何警报。 – James123

+0

这意味着这些浏览器根本没有返回文件类型,这就可以解释为什么它没有通过你的测试或文件。类型不符合你的期望。任何不使用文件扩展名而不是MIME类型的理由? – Tommy

回答

0

使用还有那些MIME类型:

application/excel 
application/x-excel 
application/x-msexcel 
+0

仍然不起作用。 – James123

+0

用这种方法GIF的作品? – MrPk