|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-02-08 14:06 UTC] sniper@php.net
[2003-02-08 14:20 UTC] rath_rat at hotmail dot com
[2003-02-08 14:26 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 14:00:01 2025 UTC |
Now here is a script that i've written to show my bug: (sorry it's so long, but this way the output is clear :) <? $tempfile="temp.txt"; if(!$fp= fopen($tempfile, "r+")) { echo "Opening file failed.\n"; } else { echo "\nReading original file..\n"; $line=fgets($fp, 4096); echo "reading $tempfile: \"$line\"..\n"; $line2=fgets($fp, 4096); echo "reading $tempfile: \"$line2\"..\n"; echo "\nWorking with \$line2\n"; $line2=explode(" ", $line2); $line2[1]++; $line2=implode(" ", $line2); rewind($fp); echo "\nRewinding $fp..\n"; $line = fgets($fp, 4096); echo "skipping the first line..\n"; fwrite($fp, $line2); echo "writing $tempfile: \"$line2\"..\n"; rewind($fp); echo "\nRewinding $fp..\n"; echo "\nOutputing file again..\n"; $line=fgets($fp, 4096); echo "reading $tempfile: \"$line\"..\n"; $line2=fgets($fp, 4096); echo "reading $tempfile: \"$line2\"..\n"; fclose($fp); } ?> temp.txt would look like this: a 1 c 5 without a trailing \n after the 5. Now what should happen is that the 5 should be incremented to 6 and get written back to the file. Under *nix this works fine, but under a windows version (sofar all that i've tried) it does not, the file is unchanged. My home platform is the Zend Development Enviroment (2.6), which runs PHP 4.2.2 or higher, under Windows XP Professional. As i mentioned earlier, under my system the file will be unchanged, but if i upload the same thing to a UNIX server, it will perform as expected and change "c 5" to "c 6". If there's no fgets() call before the fwrite(), it will work, however (although that defeats the purpose of PHP, i'd like to be able to randomly access a file :D ).