Apache 配置 Mime 类型:xlsx 文件在下载时被解释为 zip 文件,为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1647339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:20:43  来源:igfitidea点击:

Apache Config Mime Types: xlsx files are being interpreted as zip files on download, why?

apacheexcelzipmime-types

提问by dreftymac

Background:For some reason, whenever a user tries to open an xslx (excel 2007) file from our intranet using MSIE, the file download dialog interprets it as a "zip" file.

背景:出于某种原因,每当用户尝试使用 MSIE 从我们的 Intranet 打开 xslx (excel 2007) 文件时,文件下载对话框会将其解释为“zip”文件。

Admittedly, xslx files really arezip files, but we don't want that behavior. Just open in Excel, please.

诚然,xslx 文件确实zip 文件,但我们不希望出现这种行为。请在 Excel 中打开。

Question:

题:

Firefox, OTOH, opens the files normally. Is it possible that the fault is my apache configs? or is this a client-browser-only issue?

Firefox,OTOH,正常打开文件。有没有可能是我的 apache 配置出了问题?或者这是一个仅限客户端浏览器的问题?

采纳答案by Michael

The reason is IE's strange MIME sniffing behaviour: http://msdn.microsoft.com/en-us/library/ms775147.aspx. It basically tries to determine to the file type of a file by looking into its contents, somehow like Linux's filetool.

原因是 IE 奇怪的 MIME 嗅探行为:http: //msdn.microsoft.com/en-us/library/ms775147.aspx。它基本上试图通过查看文件的内容来确定文件的文件类型,有点像 Linux 的file工具。

回答by knb

You must add some new MIME-TYPES on the web-server-side.

您必须在网络服务器端添加一些新的 MIME-TYPES。

See the comment-thread on this windowsnerd.com page(from 2009):

请参阅此 windowsnerd.com 页面上评论线程(从 2009 年开始):

Add this to a .htaccess file and throw it on your site: AddType application/vnd.openxmlformats .docx .pptx .xlsx .xltx . xltm .dotx .potx .ppsx

Should fix many of the problems.

将此添加到 .htaccess 文件并将其扔到您的站点上: AddType application/vnd.openxmlformats .docx .pptx .xlsx .xltx 。xltm .dotx .potx .ppsx

应该解决很多问题。

Alternatively, you can add this to the mime.types file located in the config directory of your Apache web server

或者,您可以将其添加到位于 Apache Web 服务器的 config 目录中的 mime.types 文件中

application/vnd.ms-word.document.macroEnabled.12 .docm
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
application/vnd.ms-powerpoint.template.macroEnabled.12 potm
application/vnd.openxmlformats-officedocument.presentationml.template potx
application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam
application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm
application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
application/vnd.ms-excel.addin.macroEnabled.12 xlam
application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
application/vnd.ms-excel.template.macroEnabled.12 xltm

http://www.webdeveloper.com/forum/showthread.php?t=162526

http://www.webdeveloper.com/forum/showthread.php?t=162526