|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15117 fopen and fwrite writes to much data in mode a and a+
Submitted: 2002-01-19 17:07 UTC Modified: 2002-08-11 01:00 UTC
Avg. Score:4.0 ± 1.2
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: bitbybit at fibre dot a2000 dot nl Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 4.1.1 OS: W2K
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: bitbybit at fibre dot a2000 dot nl
New email:
PHP Version: OS:


 [2002-01-19 17:07 UTC] bitbybit at fibre dot a2000 dot nl
---- code ----
$orderstring = $date."\t".	//current time
	$tireqty." tires\t".	//received form field
	$oilqty." oil\t".	//received form field
	$sparkqty." sparks\t".	//received form field
	$totalamount."\t".	/calc. from form fields
	$address."\n";		//received form field

$fp = fopen("orders.txt", "a");
fwrite($fp, $orderstring);

---- output in orders.txt ----
22:32 19th Saturday 2002	4 tires	1 oil	12 sparks	503.80	NL
22:32 19th Saturday 2002	 tires	 oil	 sparks	0.00	
When using fopen() in mode a or a+ the last line will be added without any obvious cause.
When fopen() is used in same code but in mode w it works correct like expected.
I haven't tested fopen() in all other available modes.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-20 04:16 UTC]
Are you sure the file is empty before the fopen() call?
See for some more info...
 [2002-01-20 06:26 UTC] bitbybit at fibre dot a2000 dot nl
It doesn't really matter with fopen() in append mode. It just opens the file to append new data to the end of the file. What data will be added, depents on when(?) and what(?)data the user submitted with the form. Till that point it goes fine. But then there is this string with same time mark being added to the file. Ofcourse multiple submitions result in this same pattern being repeated over and over again.
 [2002-01-26 00:10 UTC] webmaster at lxtype dot com
Reproduced it. However, after the first two times, the same code stopped doing it (I only changed the string?). Seems to be semi-random at least, or something. Could it be a browser bug, having the page "accidentally" being submitted/reloaded?

Temporary "fix" is to conditionally open it:

if(!file_exists('orders.txt') || @file_size('orders.txt')==0)
	$fp = fopen('orders.txt', 'w');
	$fp = fopen('orders.txt', 'a');
 [2002-07-10 23:50 UTC]
Please try this snapshot:

 [2002-08-11 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, 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".
 [2007-07-30 13:19 UTC] WGFTARE at RET dot DE

'a+' Mode always insert my string two times instead of one time. It really sucks (i have to use php4 here) and this bug is so annyoing, FIX IT!
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Feb 28 18:01:23 2021 UTC