php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46023 appending data twice to file
Submitted: 2008-09-08 14:01 UTC Modified: 2008-11-01 01:00 UTC
Votes:6
Avg. Score:4.3 ± 0.9
Reproduced:6 of 6 (100.0%)
Same Version:2 (33.3%)
Same OS:1 (16.7%)
From: richard dot kuchar at gmail dot com Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5.2CVS-2008-09-08 (snap) OS: Debian (etch)
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-09-08 14:01 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-08 23:45 UTC] felipe@php.net
Do you have deleted the file before running again?
 [2008-09-09 09:11 UTC] richard dot kuchar at gmail dot com
Yes, I delete file before running script every time
 [2008-10-24 15:48 UTC] jani@php.net
I can not reproduce this with current CVS checkout of PHP_5_2 branch and using CLI. How do you run the script?
 [2008-11-01 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Oct 16 04:01:26 2019 UTC