|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
35 - 18 = ?
Subscribe to this entry?

 [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: Sun Aug 01 01:01:24 2021 UTC