php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17885 corrupted file downloads with fpassthru/fread/readfile
Submitted: 2002-06-20 16:06 UTC Modified: 2002-10-14 19:26 UTC
Votes:29
Avg. Score:4.8 ± 0.6
Reproduced:29 of 29 (100.0%)
Same Version:20 (69.0%)
Same OS:24 (82.8%)
From: dariusz at bulgaria dot com Assigned:
Status: No Feedback Package: Apache2 related
PHP Version: 4.2.1 OS: WinXP Pro
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: dariusz at bulgaria dot com
New email:
PHP Version: OS:

 

 [2002-06-20 16:06 UTC] dariusz at bulgaria dot com
OS: WinXP Pro
Apache 2.0.36
PHP 4.2.1 (module)

That's my script:

$f = "e:/web/old.zip";
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=old.zip");
header("Content-Length: " . filesize($f));
$fp = fopen($f, "rb");
while (!feof($fp))
{
	print fread($fp, 1024);
}
fclose($fp);

The script is running on a server in my local 100MBit LAN.
The first ~8kB of the downloaded file are always OK, but from there on the file is totally screwed up. Filesize is correct though.

Tried the same script with Apache 1.3.26 (also the module version) with basically the same configuration and the download works fine. Switched again to 2.0.36 and the downloads are corrupted again. This seems to happen only with large files (the one I tried is ~11MB).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-21 05:06 UTC] hholzgra@php.net
does it work with 

  $fp = fopen($f, "rb");
  fpassthru($fp);
  // no fclose() needed

or just 

  readfile($f); // might not be binary safe

?
 [2002-06-21 05:44 UTC] dariusz at bulgaria dot com
Tried it with fopen($f,"rb")/fread, with fopen($f,"rb")/fpassthru and with readfile($f). Doesn't work with all three methods.
 [2002-06-21 06:51 UTC] dariusz at bulgaria dot com
Built a little test page if someone's interested:
http://test.dariusz.info/
 [2002-06-27 06:22 UTC] dariusz at bulgaria dot com
Update: when using IMG SRC="somepic.php" where somepic.php only contains a content-type header and passes a picture file with fpassthru it doesn't work with Apache2, but it does work fine with Apache1. Apache2 sometimes shows the picture partially, sometimes not at all.

Updated my test page on http://test.dariusz.info with this one.
 [2002-06-27 06:55 UTC] dariusz at bulgaria dot com
I've been able to narrow the problem a little:

A friend of mine tried the picture scripts on his machine (Win98SE, Apache2.0.36, PHP4.2.1 module, no virtual hosts) and it worked.
My first thought was that the VHosts are the problem. So I installed Apache2 and PHP4.2.1 on my local machine (WinXP Pro, Apache2.0.36, PHP4.2.1 module) WITHOUT virtual hosts. The problem is still there - so the VHosts seem NOT to be the problem. I guess this has to be a WinXP Pro related problem then...
 [2002-07-03 08:15 UTC] loe at loe dot at
It is not os related. I have the same problem running apache 2.0.39 on linux (just the file sizes vary...)
Windows XP Apache 2.0.39 PHP 4.2.1 approx. 40k
Linux/ --"-- ~200k
 [2002-09-23 15:13 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip


 [2002-10-14 19:26 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 02 19:01:31 2024 UTC