记一下,怕忘了。
【问题描述】
本来就是一段PHP控制下载文件的问题。但是在某些操作系统和ie6下面,总是出弹出
“internet explorer cannot download”
【分析与解决】
之前改header改好过一次,但是这次怎么折腾这些报头,ie都不弹出那个[open/save]的对话框了。最后终于找到了问题的根源:
http://support.microsoft.com/kb/812935
"Internet Explorer Cannot Download" Error Message When You Use an HTTPS URL to Open an Office Document or PDF File
在微软的kb文档里面,描述了导致这个问题的原因和解决方法:
To work around this problem, make sure that Do Not Save Encrypted Files check box is not checked and that the server does not send the "Cache-Control: No Store" or the "Cache-Control: No Cache" header.
You may also be able to work around this problem by using an HREF to load the document.
Note This method does not work if the server uses the "Cache-Control: No Cache" header.
对于用户来说:
需要在ie选项->高级中去掉“Do not save encrypted pages to disk”前面的勾。如下图
对于服务器端:
1、不要发送Cache-Control: No Store 或者 Cache-Control: No Cache的header头
2、换用<a href="..."></a>这种标签来下载office或者pdf文档。(我之前是控制某个frame.src来下载文档的。)
【附件】
附上php的下载文件时的header部分代码。
header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: can-cache"); header("content-disposition: attachment;filename=$file"); fpassthru(fopen($file, "r"));