为什么docx,xl​​sx,pptx作为zip文件从web服务器下载?

在我的Apache服务器上,我已经存储了多个docx,xl​​sx pptx文件。

有些客户端浏览器认为这些文件是普通的压缩文件,并在下载时更改文件扩展名。 我如何使它不再那样做。

(使用Ubuntu服务器)

这些文件实际上是XML文档的ZIP文件。 把这个添加到Apache的.htaccess中

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

服务器没有为新的ms文件types设置适当的mimetypes

将以下内容添加到/etc/mime.types文件并重新启动Apache,问题应该得到解决。

 # Added by myname 2009-06-03 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 application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx 

http://www.webdeveloper.com/forum/showthread.php?t=162526有关于这个问题的信息

听起来像你的networking服务器正在看这些文件中的魔术数字,并看到他们是zip文件。

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

我对这个问题所涉及的服务器和客户端机器都有全面的pipe理控制,而且这些build议的解决scheme中没有一个能解决这个问题。

最后,唯一固定这个问题的是我….

1)卸载7-Zip(所以浏览器没有任何关联的zip文件)

2)(不知道这一步是否需要,但是)我然后再次下载了DOCX,(同时,它仍然被呈现为一个ZIP文件),但是,这一次我被提示什么应用程序打开它,我selectMSWORD。 我不select“总是打开MSWORD”,因为我不希望MSWORD总是打开ZIP文件。

3)重新安装7-Zip。

之后,所有后续尝试下载DOCX,实际上导致DOCX文件被下载并用相应的MSWORD应用程序打开。

注意:在你跳到结论,我只是有一个破碎的文件关联,让我确认,当这个问题发生时,我可以双击任何在浏览器中的DOCX和MSWORD将始终打开它。 这个问题总是只发生在试图用IE8下载/打开一个DOCX的时候。 FF4和Chrome都完美无缺。 我试图在服务器端添加合适的MIMEtypes到/ etc / mime-types和.htaccess。 我也尝试禁用“打开基于内容的文件,而不是文件扩展名”(但这只会导致浏览器打开DOCX为不可读的ASCII文本),将FEATURE_MIME_ *registry项设置为“0”,并将服务器URL添加到“可信站点”列表。 再次,没有这些似是而非的逻辑解决scheme为我工作。

下载http://packages.ubuntu.com/oneiric/mime-support ,并使用dpkg -i进行安装。 工作很好!

PS:Ubuntu和Debian上的Apache从/etc/mime.types中读取