|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 21:00:01 2025 UTC |
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.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).