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:7
Avg. Score:4.3 ± 0.9
Reproduced:7 of 7 (100.0%)
Same Version:3 (42.9%)
Same OS:2 (28.6%)
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: richard dot kuchar at gmail dot com
New email:
PHP Version: OS:

 

 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 07:01:31 2024 UTC