Bug #10989: Wrong file writing

From: Date: Mon, 21 May 2001 08:57:52 +0000
Subject: Bug #10989: Wrong file writing
Groups: php.dev 
Request: Send a blank email to php-dev+get-56017@lists.php.net to get a copy of this message
From: trax102@hotmail.com Operating system: Win2K-Win98-UNIX PHP version: 4.0 Latest CVS (2001-05-21) PHP Bug Type: Filesystem function related Bug description: Wrong file writing <?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); ?> -- Edit Bug report at: http://bugs.php.net/?id=10989&edit=1

« previous php.dev (#56017) next »