|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-10-08 13:52 UTC] adam at net-europa dot com
The following code:
$size = filesize($file);
header("Pragma: no-cache");// HTTP/1.0
header("Cache-Control: no-cache, must-revalidate");// HTTP/1.1
header("Content-Type: application/octet-stream");
if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT))
header("Content-Disposition: filename=$userfile");
else
header("Content-Disposition: attachment; filename=$userfile");
header("Content-Length: $size");
header("Content-Transfer-Encoding: binary\n");
fpassthru($fp);
when run under Linux/Apache results in a zero length file on MS IE 5.5 when connecting via an ISP or proxy. I have tried various ISPs all with the same result. All is fine with Netscape, or with a direct LAN connection.
Also, if the same PHP script is run under Windows NT 4.0 / IIS 5.0 all is well.
By removing the line: header("Content-Length: $size"); the download is successful, but we lose any progress bar so this workaround is far from ideal.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 13:00:01 2025 UTC |
The following code: $size = filesize($userfile); $fp=fopen($userfile,"r"); header("Pragma: no-cache");// HTTP/1.0 header("Cache-Control: no-cache, must-revalidate");// HTTP/1.1 header("Content-Type: application/octet-stream"); if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) header("Content-Disposition: filename=$userfile"); else header("Content-Disposition: attachment; filename=$userfile"); header("Content-Length: $size"); header("Content-Transfer-Encoding: binary\n"); fpassthru($fp); when run under Linux/Apache results in a zero length file on MS IE 5.5 when connecting via an ISP or proxy. I have tried various ISPs all with the same result. All is fine with Netscape, or with a direct LAN connection. Also, if the same PHP script is run under Windows NT 4.0 / IIS 5.0 all is well. By removing the line: header("Content-Length: $size"); the download is successful, but we lose any progress bar so this workaround is far from ideal.Here is your code, altered slightly $userfile = "file.xls"; $size = filesize($userfile); $fp=fopen($userfile,"r"); header("Pragma: no-cache");// HTTP/1.0 header("Cache-Control: no-cache, must-revalidate");// HTTP/1.1 header("Content-Type: application/octet-stream"); if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) { $header = "Content-Disposition: filename=".$userfile; //header("Content-Disposition: filename=$userfile"); }else { $header = "Content-Disposition: attachment; filename=".$userfile; //header("Content-Disposition: attachment; filename=$userfile"); } header($header); $header_str = "Content-Length: ".$size; header($header_str); header("Content-Transfer-Encoding: binary\n"); fpassthru($fp); Hope this works.