php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15613 readfile doesn't work correctly with WIndows XP
Submitted: 2002-02-19 03:11 UTC Modified: 2002-04-29 15:39 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: khoukaz at web dot de Assigned:
Status: Closed Package: Output Control
PHP Version: 4.1.1 OS: Windows XP (Professional)
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
34 - 5 = ?
Subscribe to this entry?

 
 [2002-02-19 03:11 UTC] khoukaz at web dot de
I use a script like the following for downloading files (images, ascii, ...) :

<?
$link = $save_as_name = "test.tif"; // or *.bmp, *.txt, ...
$size = filesize($link);

header("Content-Type: application/octet-stream");
header("Content-disposition: inline; filename=\"".$save_as_name."\"");
header("Content-Length: $size");
header("Content-Transfer-Encoding: binary\n");

readfile($link);  // or fpassthru instead of readfile

//$fp = fopen($link, "r");
//fpassthru($fp);
//fclose($fp);
?>

Under Win NT/2000 it works fine, but under XP i get a distorted image after downloading and opening the file. Also text files differ from the original one.

I use Apache 1.3.22 and PHP 4.1.1 as module.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-19 04:53 UTC] wez@php.net
You're not using the auto-fit image to window option
in IE 6 are you?
 [2002-02-19 05:09 UTC] khoukaz at web dot de
No, it's not a problem of the image presentation. The files (the original and the downloaded one) differ. The same probleme occurs with text files. Below you will find a comparision between an original text file and what the download makes of it:

------- a cutting of apache httpd.conf ----------------

#LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule php4_module modules/php4apache.dll

#
#  Reconstruction of the complete module list from all available modules
#  (static and shared ones) to achieve correct module execution order.
#
# The modules listed below, without a corresponding LoadModule directive,
# are static bound into the standard Apache binary distribution for Windows.
#
# Note: The order in which modules are loaded is important.  Don't change
# the order below without expert advice.
#
# [WHENEVER YOU CHANGE THE LOADMODULE SECTION ABOVE, UPDATE THIS TOO!]
ClearModuleList
#AddModule mod_vhost_alias.c
AddModule mod_env.c
AddModule mod_log_config.c
#AddModule mod_mime_magic.c
...
-------------------------------------------------------





--------------- the downloaded part -------------------
#LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule php4_module modules/php4apache.dll

#
#  Reconstruction of the complete module list from all available modules
#  (static and shared ones) to achieve correct module execution order.
#
# The modules listed below, without a corresponding LoadModule directiveRCRD(.	.?`?.....p??..h......?`?....Y?........?..?.........`?....?`?....?`?....?.........h..............(.??...........?......??.....FILE0..?`?......8..?................?_............`...........H......,?ټ??,?ټ??,?ټ??,?ټ?? ...................\..................0...x..........Z.....[.....,?ټ??,?ټ??,?ټ??,?ټ??................ .......R.E.S.U.L.T.~.3...H.T.M.t.m...0...x..........^.....[.....,?ټ??,?ټ??,?ټ??,?ټ??................ .....Y?r.e.s.u.l.t.s.[.2.]...h.t.m...?...................?????yGH`?....`?............(..........h.............(...(.....................Z???..S`?....................@..........h.............(...(....?.....?......??.....?...................a`?....S`?....S`?....p..........h.............(.H.p.....?.....?......??.....?...H.................????????@...................................?3<?u`?....a`?....a`?....0..........h.............(..(..?.................R?...Y?~.....?`?....u`?....u`?....X..........h.............(..@....?.....?......??....................................................?`?....?`?....?`?....8..........h...........	.	.(..0....?@....?......??.....!~.???....?3<??`?....?`?............(..........h.............(...(.....................????.y??`?....................0..........h.............(..(..?................T?.....@.....?`?....?`?....?`?....H..........h...........	.	.(..8....?E....?....Y???......???w?......=??Aف.....?`?....?`?....?`?....X..........h.............(..@....?.....?......??...... ......_......_.......@......_......_......?`?....?`?....?`?....?..........h.............(.8.`.8.?...?...........˽.....ʦv???~k{???~k{???~k{???. ......_...... .......ʦv???~k{???~k{???~k{???.@......_...... .......?`?....?`?....?`?....?..........h......
.......(.8.`.8.?...P...........˽.....ʦv???~k{???~k{???~k{???. ......_....Y? .......ʦv???~k{???~k{???~k{???.@......_...... .......`?....?`?............(..........h.............(...(.....................?x?<U?`?....................?..........h.............(.0.X.0...8.0....?......??.....:???? ...................\..................??՗?? ...................\..................*`?....`?....`?....?..........h.............(.8.`.8.?...	...........˽.....??՗????՗????՗??:????. ............. .......??՗????՗????՗????՗?Y?. ............. .......C`?....*`?....*`?....?..........h.............(.8.`.8.?...?	...........˽.....??՗????՗????՗??:????. ............. .......??՗????՗????՗????՗??. ............. .......\`?....C`?............(..........h.............(...(.....................???<U?g`?....................?..........h.............(.0.X.0...8.0................:????....................t..................???b???....................t..................~`?....g`?..Y?g`?....?..........h.............(.8.`.8.?..............?.....?(??????$^b????$^b???:????.......................?(??????$^b????$^b??????b???.......................?`?....~`?............(..........h.............(...(.....................????????`?....................0..........h.............(..(..?.........................?`.....?`?....?`?....?`?....(..........h..............(...(............$......??.....?`?....?`?....?`?....?..........h.............(.Y??...@...?............p?.....?`.....?.n.....[.....:????:????:????:????................ .......A.r.c.h.i.v.e.0.0.0.0.0.0.0.1.[.1.]...j.p.g...?`?....?`?....?`?....?..........h.............(.p.?...@...8............p?.....?`.....p.Z.....[.....:????:????:????:????................ .......A.R.C.H.I.V.~.1...J.P.G.g.i.f.?`?....?`?....?`?....?.........h.............
(.??...........$......??.....FILE0..?`?......8..?................?`............`.Y?RCRD(.	.?!`?.....p??..X......?!`?....Z?....?......c.?..............H......:????:????:????:???? ...................\..................0...x..........Z.....[.....:????:????:????:????................ .......A.R.C.H.I.V.~.1...J.P.G.0.0.1.0...?..........n.....[.....:????:????:????:????................ .......A.r.c.h.i.v.e.0.0.0.0.0.0.0.1.[.1.]...j.p.g...?...................?????yG7 `?....?`?............(..........h.............(...(...........Z?........b?Q?,.,.B `?....................@..........h.............(...(....?.....$......??.....?...................P `?....B `?....B `?....p..........h.............(.H.p.....?.....$......??.....?...H.................????????@...................................?3<?d `?....P `?....P `?....0..........h.............(..(..?................n?.....n.....p `?....d `?....d `?....X..........h.............(..@....?.....$......??...... ....................................Z?........? `?....p `?....p `?....8..........h...........	.	.(..0....?@....$......??.....1n.??....?3<?? `?....? `?............(..........h.............(...(.....................????.?
?? `?....................X..........h.............(..@....?.....$......??...... ..............?....... ......................? `?....? `?....? `?....?..........h.............(.8.`.8.@...?............p?.....:????:????:????:????. ......?...... .......:????:????:????:???Z?................ .......? `?....? `?....? `?....?..........h.............(.8.`.8.@...8............p?.....:????:????:????:????. ......?...... .......:????:????:????:????................ .......? `?....? `?............(..........h.............(...(.....................??
?<U?? `?....................?..........h.............(.0.X.0...8.0................:???? ...................w..................p????? ...................w..................? `?....? `?..Z?? `?....?..........h.............(.8.`.8.?...?............7?......?='????p?????p?????:????.?.......?...... .......?='????p?????p?????p?????.?.......?...... .......!`?....? `?............(..........h.............(...(.....................???????"!`?....................?..........h.............(.@.h.@...8. ...."......??.....:????:????:???? ...................w..................ʦv???ʦv???ʦv??? ...................w..................=!`?...."!`?...."!`?..Z??..........h.............(.8.`.8.?...............7?......0?????:????:????:????.............. .......0?????ʦv???ʦv???ʦv????.......?....... .......V!`?....=!`?............(..........h.............(...(.....................???????a!`?....................?..........h.............(.8.`.8.?...............7?......0?????:????:????:????.............. .......0?????:????:????:????.............. .......z!`?....a!`?............(..........h.........Z?..(...(.....................????????!`?....................0..........h.............(..(..?................Z?.....9n.....?!`?....?!`?....?!`?....?..........h.............(...(.p.l...?.............'?.....y`.....p.Z.....[.....???j??????j??????j??????j???. ......?...... .......A.R.9.5.E.5.~.1...J.P.G.0.0.4.?!`?....?!`?....?!`?....?..........h.............(...(.?.l...?............'?.....y`.....?.n.....[.....???j??????j??????j??????j???. ......?...... .......A.r.Z?h.i.v.e.0.0.0.0.0.0.0.1.[.1.]...j.p.g.0.?!`?....?!`?....?!`?....H..........h.............(...(.................??.....FILE0..?aU?......8..?......?!`?....?!`?....?!`?....0..........h.............(..(..?.........................y`.....?!`?....?!`?............(..........h............
.(...(.........................p???!`?....................?..........h............(.@.h.@...8. .....z......l.....?n?????n?????n???? ...................l..................~?????~????Z? such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain

#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type.  The MIMEMagicFile
...
----------------------------------------------------------




The size of the files is always correct.
 [2002-02-19 05:25 UTC] wez@php.net
Yuk!
Do you have output buffering enabled, and/or gzip compression?
(Just to confirm).
 [2002-02-19 05:34 UTC] khoukaz at web dot de
No output buffering, no compression.
 [2002-02-20 03:23 UTC] khoukaz at web dot de
Now i turned implicit_flush in the php.ini to on (see Bug #15245), but this doesn't matter.

Please let me know, if you need more information.
 [2002-03-06 04:48 UTC] khoukaz at web dot de
I could solve the problem with binary files by using fread instead of readfile:

<?
$link = $save_as_name = "test.tif"; // or *.bmp, *.txt, ...
$size = filesize($link);

header("Content-Type: application/octet-stream");
header("Content-disposition: inline; filename=\"".$save_as_name."\"");
header("Content-Length: $size");
header("Content-Transfer-Encoding: binary\n");

$fp = fopen($link, 'rb') or print('Could not open file!'); 
$read = fread($fp, $size) or print('Could not read file'); 
fclose($fp);
print($read); 
?>

But this only works with binary files. With text files a get the same problems (see above).
 [2002-03-20 00:00 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".
 [2002-03-20 02:22 UTC] khoukaz at web dot de
The bug is not fixed. The problems are still present.
By the way, fread doesn't work well with all files.

The problems only occur under Windows XP.
 [2002-03-20 06:22 UTC] sander@php.net
Reopening.
 [2002-03-20 07:37 UTC] wez@php.net
Does this happen if you use CGI under XP?
I suspect that this might be apache related.

--Wez.
 [2002-03-20 07:57 UTC] wez@php.net
I meant to say: please try running the CGI both under
apache and from the command line.

 [2002-03-20 14:18 UTC] khoukaz at web dot de
Yes, you are right. If i call the script as CGI under apache it works fine. If i start it from the command line, i get a message, that the script cannot open the file i want to read. With PHP as apache module i get the problems described above.

Unfortunately i cannot use PHP as CGI.

What do you mean with 'apache related'. Is it a bug in apache or in PHP? Shall i write a bugreport to apache?


Thanks,
 [2002-03-20 14:53 UTC] wez@php.net
I think the bug *may* be a bug in apache under Windows XP.
Is there any chance you can test the same script on Win2k
or NT? (Just to narrow that part down too).

I'll ask the sapi/apache guys here about this problem;
we did discuss this a while ago and I think the general
opinion was that it was related to apache; if you could
write a bug report to apache (or just check to see if
anyone else has the same problem) that will get more
heads thinking about it :-)

Derick (if you are reading this), I'm marking this as
critical meaning that it should be fixed for PHP 4.2

 [2002-03-21 03:07 UTC] khoukaz at web dot de
Yes, i have tested the script on Win NT and Win2000. There are no problems. So it is really a problem of Win XP + PHP as module.
 [2002-03-26 03:12 UTC] derick@php.net
Not critical
 [2002-04-29 04:02 UTC] khoukaz at web dot de
The bug is fixed with Apache 1.3.24
 [2002-04-29 15:39 UTC] sniper@php.net
Closed then.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 11:01:28 2024 UTC