apache 设置mime

accphe配置,添加 AddType application/x-httpd-php .php AddType application/x-httpd-php .html AddType
accphe配置,添加
AddType application/x-httpd-php .php
AddType application/x-httpd-php .html
AddType application/x-httpd-php .fuck


在httpd.conf里面添加就行
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx


AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document docx






IE下载docx(xlsx,pptx)文件时,会自动将扩展名变为zip


一、机制    


IE下载docx(xlsx,pptx)扩展名的文件时,会自动将扩展名变为zip。


    当我们从IIS或者Tomcat之类的Web服务器通过二进制流下载dotx,docx,pot,xlsx,pptx等后缀的文件时,如果下载后变成zip格式的文件,那么是由于IE中对下载文件类型的判断,假如找不到相应后缀的MIME的话,会自动根据数据流来判断文件的类型,而微软对Office2007的格式做了和以前完全不同的处理。
    以前的Office文档是100%的二进制格式。第三方的工具操作起来非常不方便,而Office2007从整体上都是基于XML格式的,这里并不是说Office2007文档可以保存成XML格式。而是Office2007默认的文档格式就是XML的(Word的docx、Excel的xlsx等)。docx本质上是一个zip文件,里面有一系列的xml、目录和其他的文件。如果我们将docx改成zip。就可以用winzip等软件将其解开。正是由于这样的原因,当MIME中不存在相对应的Office2007类型的情况下,被自动识别为ZIP文件了。
    要解决该问题,是需要在Server端进行更改的,也就是说我们客户端的计算机并没有问题。








   形象一点:浏览器请求一个url路径,这个路径指向一个.pptx文件,apache从web服务器的目录(磁盘上)查到这个文件,但它不知道这个文件是什么类型(注意:文件类型并不是由文件名后缀决定的,而是文件本身内容所决定),于是它通过分析这个文件内容,发现这个文件像是个zip压缩档,文件大小为12345字节,于是它给浏览器说:“嘿,你请求的是个zip压缩文件,它的大小为12345个字节,文件名是 abcd.pptx 。下面是这个文件的内容,请接收”


浏览器收到消息后,得知apache要发给自己一个zip压缩档,于是一边弹出对话框、询问用户是直接打开、还是保存到硬盘,一边把apache接下来发回的数据保存到缓冲区(或者保存到硬盘的临时目录里),等用户做好选择后,采取相应的打开或是保存的操作。




二、方案   
问题解决:第一步将服务器上的office由2003升级到2007;


                  第二步在iis中点“本地计算机”属性,在弹出窗口中,设置MiME类型。增加.docx和.xlsx的相应解析。例如:点击新建按钮,弹出对话框中,扩展名处填写.doc,在MIME类型处填“application/msword”。


                  第三步在项目的网站名上点击右键属性,在打开的网站属性窗口中找到“http头选项卡”,找到MIME设置,具体设置如第二步中一样,加入.doc/.docx/.xls/.xlsx;


                  第四步重启IIS。




附上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
application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx
三、更好的方案


建议不要去修改 /etc/mime.types ,添加MIME type的推荐方法是使用apache的 AddType 指令.


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
可以把这些指令加到apache的配置文件里,该指令在apache里出现过N次,不需多说,照着加进去就对了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值