note 22023 deleted from function.fread by dams
| From: | dams@php.net | Date: | Tue, 04 Jun 2002 12:01:10 +0000 |
| Subject: | note 22023 deleted from function.fread by dams | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-31424@lists.php.net to get a copy of this message | ||
WARNING : HAZY ERROR DUE TO FILESYSTEM !
THIS CODE :
// get contents of a file into a string
$filename = "/usr/local/something.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
GOT AN ERROR.
(under linux v2.2.4)
I explain:
I did a change in the file's length, by ADDING some characters, then CLOSED the file, used this
code to GET the whole file in another function, an the filesize was still the OLD filesize (without
the extra characters).
So I got the whole file BEFORE I added the characters.
I worked it around with filesize()+1024 but this isn't a proper solution.
This hazy error may occur for some other filesystem than the ext2 of linux 2.2.4. Be careful !!!