php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13601 File download with Content-Length specified fails with IE5.5
Submitted: 2001-10-08 13:52 UTC Modified: 2001-11-22 02:46 UTC
From: adam at net-europa dot com Assigned:
Status: Closed Package: Apache related
PHP Version: 4.0.6 OS: Linux (Red Hat 7)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: adam at net-europa dot com
New email:
PHP Version: OS:

 

 [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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-08 13:55 UTC] adam at net-europa dot com
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.


 [2001-10-21 01:08 UTC] sniper@php.net
Is the $size correct for the file?


 [2001-10-22 03:58 UTC] adam at net-europa dot com
Yes.

In the script,

$size=filesize($file);

Where $file is the filename and path.

To prove that it's correct, I have printed the value. Also, both NS and IE (when it works, ie. not through a proxy), display the correct file size and bytes remaining, etc.


 [2001-10-23 06:23 UTC] sniper@php.net
I would guess this has something to do with proxy being 
in between..is there one?

--Jani

 [2001-11-14 06:41 UTC] sander@php.net
No feedback. Closing.
 [2001-11-20 06:55 UTC] adam at net-europa dot com
As stated in my original submission, EITHER going through a proxy, OR simply dialling up through an ISP, you get the problem.

Connecting directly over a LAN, you do not.

Please re-open.
 [2001-11-21 12:25 UTC] sniper@php.net
Are you sure there isn't some transparent proxy involved?

 [2001-11-22 02:46 UTC] adam at net-europa dot com
Not tham I am specifically aware of, but it is highly possible that my ISP (BT Internet) has some kind of proxy.

Incidentally, I have tried a couple of different ISPs with the same result.

I would guess that this IS a proxying-related issue.
 [2002-10-18 13:08 UTC] tlepkowski at comcast dot net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 00:01:32 2024 UTC