ID: 10989
User Update by: [EMAIL PROTECTED]
Old-Status: Open
Status: Closed
Bug Type: Filesystem function related
Operating system: Win2K-Win98-UNIX
PHP Version: 4.0 Latest CVS (2001-05-21)
Description: Wrong file writing

Ok, I've found the solution: simply call clearstatcache() before filesize().

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

[2001-05-21 10:57:52] [EMAIL PROTECTED]
<?php
//At the end of the script "test.txt" should 
//contains "ADD1ADD2", but, as you can see,
//it will contains just "ADD2".
//Is there a work around for this problem ?

function read_file ($file_name)
{
        $file = fopen($file_name, "r");
        flock($file, 1); 
        $content = trim(fread($file, filesize($file_name)));
        flock($file, 3); 
        fclose ($file);
        return ($content);
}

function write_file ($content, $file_name)
{
        $file = fopen($file_name, "w");
        flock($file, 2);
        fwrite($file, $content);
        flock($file, 3);
        fclose ($file);
}

$filename="test.txt";
write_file("", $filename);

$content = read_file($filename);
$content .= "ADD1";
write_file($content, $filename);

$content = read_file($filename);
$content .= "ADD2";
write_file($content, $filename);
?>

---------------------------------------------------------------------------


Full Bug description available at: http://bugs.php.net/?id=10989


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to