#46023 [Opn->Fbk]: appending data twice to file

From: Date: Fri, 24 Oct 2008 15:48:48 +0000
Subject: #46023 [Opn->Fbk]: appending data twice to file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-130052@lists.php.net to get a copy of this message
ID: 46023 Updated by: jani@php.net Reported By: richard dot kuchar at gmail dot com -Status: Open +Status: Feedback Bug Type: Filesystem function related Operating System: Debian (etch) PHP Version: 5.2CVS-2008-09-08 (snap) New Comment: I can not reproduce this with current CVS checkout of PHP_5_2 branch and using CLI. How do you run the script? Previous Comments: ------------------------------------------------------------------------ [2008-09-09 09:11:31] richard dot kuchar at gmail dot com Yes, I delete file before running script every time ------------------------------------------------------------------------ [2008-09-08 23:45:38] felipe@php.net Do you have deleted the file before running again? ------------------------------------------------------------------------ [2008-09-08 14:01:15] richard dot kuchar at gmail dot com Description: ------------ opening file in append mode and writing to file wrote data twice to file Reproduce code: --------------- <?php $filename = 'test.txt'; $somecontent = "Add this to the file\n"; // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } fclose($handle); ?> Expected result: ---------------- in 'test.txt': Add this to the file\n Actual result: -------------- in 'test.txt': Add this to the file\nAdd this to the file\n ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46023&edit=1

« previous php.bugs (#130052) next »