php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15553 fopen() when using r+ overwrites whateva is at top
Submitted: 2002-02-14 09:35 UTC Modified: 2002-02-14 14:15 UTC
From: smythe at smythey dot org Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.1.1 OS: Win2K
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: smythe at smythey dot org
New email:
PHP Version: OS:

 

 [2002-02-14 09:35 UTC] smythe at smythey dot org
<?
$output = "\nGday.\n";
$directory = dirname($path_translated);
$filename = fopen($directory . "members/addop.txt", "r+", 1) or die("Can't open file");
if ($output) { 
$written = fwrite($filename, $output) or die ("Couldn't write to file");
}
fclose($filename);
?>

When usin r+ it writes to the file addop.txt but just overwrites whateva is at the top. i want it to just add to the top of the file. 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-14 14:15 UTC] torben@php.net
That's 'cause that what 'r+' does:

  http://www.php.net/fopen

The underlying system call does not support prepending to
files--this is a pretty common request, in fact. For
solutions, please ask on the php-general@lists.php.net
support list or check out http://www.php.net/support.php
for help.


Torben
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 14:01:33 2025 UTC