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

From: Date: Mon, 08 Sep 2008 23:45:39 +0000
Subject: #46023 [Opn->Fbk]: appending data twice to file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-128790@lists.php.net to get a copy of this message
ID: 46023 Updated by: felipe@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: Do you have deleted the file before running again? Previous Comments: ------------------------------------------------------------------------ [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 (#128790) next »