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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 23:01:27 2024 UTC