php.net |  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
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: 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.

Manu.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-19 07:40 UTC] sander@php.net
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-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 15:01:31 2025 UTC