|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-04-29 08:03 UTC] gfraley5 at earthlink dot net
This code snippet demonstrates the problem. Under 4.3.1 and prior, it functions correctly. Under 4.3.2 (all versions) it does not function the same and is actually wrong.
<?
$myArray[] = 'msgid'."\r\n";
$myArray[] = '1049987091'."\r\n";
$myArray[] = '1050930128'."\r\n";
$fp = fopen("problemFile.php",'w') or die("Unable to open file");
for ($i=0;$i<count($myArray);$i++) {
if ($i==0) $prefx = "<? Header(\"HTTP/1.0 403 Forbidden\");exit;?>\r\n";
else $prefx = "";
fwrite($fp,$prefx.$myArray[$i]);
}
fclose($fp);
echo nl2br(readfile("problemFile.php"));
?>
Under 4.3.1 and prior, here is the output of problemFile.php:
<? Header("HTTP/1.0 403 Forbidden");exit;?>
msgid
1049987091
1050930128
Under 4.3.2, here is the output of problemFile.php. Notice the difference in the behaviour of the \r\n:
<? Header("HTTP/1.0 403 Forbidden");exit;?>
msgid
1049987091
1050930128
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 09:00:02 2025 UTC |
fopen("problemFile.php",'wb') Does that help? Also, check the line endings in the actual file (not in the output generated by php), and your auto_detect_line_endings ini setting.I can't reproduce this here (tried 4.2.1 and 4.3.2 under XP). NOTE: readfile() returns the number of bytes it wrote, NOT the contents of the file. Use file_get_contents() for that. Please try this script on 4.3.2 and your 4.2.3 and report back (paste the output from each into this report): <?php $myArray[] = 'msgid'."\r\n"; $myArray[] = '1049987091'."\r\n"; $myArray[] = '1050930128'."\r\n"; $l = 0; $fp = fopen("problemFile.php",'w') or die("Unable to open file"); for ($i=0;$i<count($myArray);$i++) { if ($i==0) { $prefx = "<? Header(\"HTTP/1.0 403 Forbidden\");exit;?>\r\n"; } else { $prefx = ""; } $l += fwrite($fp, $prefx.$myArray[$i]); } fclose($fp); echo "Wrote: $l bytes; filesize is now " . filesize("problemFile.php") . "\n"; echo "==== using readfile =====\n"; $x = readfile("problemFile.php"); echo "==== readfile read $x bytes ====\n"; echo "==== using fopen 'r' ===\n"; $fp = fopen("problemFile.php", "r"); while (!feof($fp)) { echo fgets($fp); } fclose($fp); echo "==== using fopen 'rb' ===\n"; $fp = fopen("problemFile.php", "rb"); while (!feof($fp)) { echo fgets($fp); } fclose($fp); echo "==== done ===\n"; ?>I believe I may have run into this exact same problem after upgrading to 4.3.2 ("gold" by now) (Apache SAPI) from 4.3.1 (Apache SAPI) on WinXP/Apache 1.3.27. I am running Gallery (on sourceforge) on my web site and found that users submitting photos broke the database; Gallery uses serialize and deserialize to store it's often large objects as files, and the \r\n vs \n used in objects that get serialized as files, breaks the object's file. Since this "bug" seems to be still out in the open and appears to be on the fence for Bogus, I am thinking the Gallery dev should know about this new and special Win32/PHP4.3.2 problem and bend accordingly... unless of course, I am barking up the wrong tree.