ID: 46023
Updated by: [EMAIL PROTECTED]
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