From: [EMAIL PROTECTED] Operating system: Windows XP Pro / UNIX PHP version: 4.2.2 PHP Bug Type: Filesystem function related Bug description: succesive fgets() and fwrite() calls
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 ). -- Edit bug report at http://bugs.php.net/?id=22124&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=22124&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=22124&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=22124&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=22124&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=22124&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=22124&r=support Expected behavior: http://bugs.php.net/fix.php?id=22124&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=22124&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=22124&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=22124&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22124&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=22124&r=dst IIS Stability: http://bugs.php.net/fix.php?id=22124&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=22124&r=gnused