本文介绍了文件下载在IE6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我已经遇到了一个与IE6相当的整合(令人沮丧的)问题。我们正在提供一些服务器生成的pdf,然后简单地在PHP中设置标题来强制浏览器下载该文件。工作正常,除IE6之外,只有只有,如果Windows用户帐户设置为标准用户(即不是管理员)。



由于这是一个企业环境,当然所有的帐户都是这样设置的。奇怪的是,在下载对话框中,Content-Type不能被识别:

  header('Pragma:public') ; 
header('Expires:0');
header('Cache-Control:must-revalidate,pre-check = 0,post-check = 0');
header('Cache-Control:public');
header('Content-Description:File Transfer');
header('Content-Type:application / pdf');
header('Content-Disposition:attachment; filename =xxx.pdf');
header('Content-Transfer-Encoding:binary');
echo $ content;
退出;

我还尝试将文件内容首先写入临时文件,以便我也可以设置 Content-Length ,但没有帮助。

解决方案

是假的!



 内容转移编码:二进制

这个头是从电子邮件头复制的。它不适用于HTTP,因为HTTP不具有任何其他传输模式,而不是二进制。设置它使得设置 X-Bits-By-Byte:8

  Cache-control:pre-check = 0,post-check = 0 

这些非标准值定义IE应检查缓存内容是否仍然新鲜。 0 是默认值,因此将其设置为 0 是浪费时间。这些指令仅适用于可缓存的内容,而 Expires:0 must-revalidate -cacheable。

 内容描述:文件传输

这是另一个电子邮件模仿。 这个标题不会以任何方式影响下载。它只是信息丰富的自由格式的文本。它在技术上与 X-Hi-Mom有用:我发送一个文件!头。

  header('Cache-Control:must-revalidate,pre-check = 0,post-check = 0'); 
header('Cache-Control:public');

在PHP第二行完全覆盖第一个。你似乎在黑暗中刺伤。



真正有什么区别



 内容处理:附件

您不必在其中插入文件名(可以使用 mod_rewrite index.php / fakefilename.doc 技巧 - 它可以更好地支持特殊字符,并在浏览器中工作忽略可选 Content-Disposition 标题)



在IE中,文件是否在缓存中(打开不适用于不可缓存的文件),以及用户是否具有声称支持IE检测到的文件类型的插件。



要禁用缓存,您只需要缓存控制:无缓存(不带20个额外的假标头),并使文件可缓存,您不必发送任何东西。



注意:PHP有可怕的错误称为 session.cache_limiter 这绝对拧紧了HTTP标头,除非ÿ ou将它设置为 none

  ini_set(' session.cache_limiter, '无'); //告诉PHP停止拧紧HTTP 


I've come across a rather interesing (and frustrating) problem with IE6. We are serving up some server generated pdfs and then simply setting headers in PHP to force a browser download of the file. Works fine and all, except in IE6 but only if the windows user account is set to standard user (ie. not administrator).

Since this is for a corporate environment, of course all their accounts are setup this way. Weird thing is, that in the download dialog, the Content-Type is not recognized:

header( 'Pragma: public' );
header( 'Expires: 0' );
header( 'Cache-Control: must-revalidate, pre-check=0, post-check=0' );
header( 'Cache-Control: public' );
header( 'Content-Description: File Transfer' );
header( 'Content-Type: application/pdf' );
header( 'Content-Disposition: attachment; filename="xxx.pdf"' );
header( 'Content-Transfer-Encoding: binary' );
echo $content;
exit;

I also tried writing the file content to a temporary file first so I could also set the Content-Length in the header but that didn't help.

解决方案

These headers are bogus!

Content-Transfer-Encoding: binary

This header is copied from e-mail headers. It doesn't apply to HTTP simply because HTTP doesn't have any other mode of transfer than binary. Setting it makes as much sense as setting X-Bits-Per-Byte: 8.

Cache-control: pre-check=0, post-check=0

These non-standard values define when IE should check whether cached content is still fresh. 0 is the default, so setting it to 0 is waste of time. These directives apply only to cacheable content, and Expires:0 and must-revalidate hint that you wanted to make it non-cacheable.

Content-Description: File Transfer

This is another e-mail copycat. By design this header doesn't affect download in any way. It's just informative free-form text. It's technically as useful as X-Hi-Mom: I'm sending you a file! header.

header( 'Cache-Control: must-revalidate, pre-check=0, post-check=0' );
header( 'Cache-Control: public' );

In PHP second line completely overwrites the first one. You seem to be stabbing in the dark.

What really makes a difference

Content-Disposition: attachment

You don't have to insert filename there (you can use mod_rewrite or index.php/fakefilename.doc trick – it gives much better support for special characters and works in browsers that ignore the optional Content-Disposition header).

In IE it makes difference whether file is in cache or not ("Open" doens't work for non-cacheable files), and whether user has plug-in that claims to support type of file that IE detects.

To disable cache you only need Cache-control:no-cache (without 20 extra fake headers), and to make file cacheable you don't have to send anything.

NB: PHP has horrible misfeature called session.cache_limiter which hopelessly screws up HTTP headers unlesss you set it to none.

ini_set('session.cache_limiter','none'); // tell PHP to stop screwing up HTTP

这篇关于文件下载在IE6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:28