ID:               22124
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Verified
 Bug Type:         Filesystem function related
 Operating System: Windows XP Pro / UNIX
-PHP Version:      4.2.2
+PHP Version:      4.3.1-dev
 New Comment:

Does seem to work quite right in Linux either (using PHP 4.3.1-dev from
today)



Previous Comments:
------------------------------------------------------------------------

[2003-02-08 13:36:42] [EMAIL PROTECTED]

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 this bug report at http://bugs.php.net/?id=22124&edit=1

Reply via email to