|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13667 fread doesn't works when the file opened with 'w+'
Submitted: 2001-10-14 17:45 UTC Modified: 2001-10-19 07:40 UTC
From: manu at chasqui dot uclv dot edu dot cu Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.0.6 OS: Windows 2000 Advanced Server
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: manu at chasqui dot uclv dot edu dot cu
New email:
PHP Version: OS:


 [2001-10-14 17:45 UTC] manu at chasqui dot uclv dot edu dot cu
$fh = fopen('myfile.txt', 'w+');
$content = fread( $h, filesize('myfile.txt'));
echo $content;
fseek( $fh, 0 );
fwrite( $fh, $newcontent );
ftruncate( $fh, strlen( $newcontent ) );

No matters de contents of myfile.txt, no output is generated. 
If I replace the first line to 
$fh = fopen('myfile.txt', 'r+');
everythings works fine if the file exists.



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-19 07:40 UTC]
From the docs:
"... place the file pointer at the beginning of the file and truncate the file to zero length"
I don't think there is much to read from a zero-length file...
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Sep 20 09:03:36 2021 UTC