note 62926 deleted from function.filesize by aharvey
| From: | aharvey@php.net | Date: | Tue, 22 Jan 2013 00:20:27 +0000 |
| Subject: | note 62926 deleted from function.filesize by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193330@lists.php.net to get a copy of this message | ||
Note Submitter: mkamerma at science dot uva dot nl
----
When read/writing binary files you often cannot rely on the feof() function being of much use, since
it doesn't get triggered if the pointer is at the eof but hasn't tried to read one more
byte. In this case you instead need to check if the file pointer is at filesize yet, but if you
don't have the filename handy, you need to pluck it out fstat all the time. Two simple
functions that would be nice to have natively in PHP:
<?php
function fpfilesize(&$fp) { $stat = fstat($fp); return $stat["size"]; }
function fpeof(&$fp) { return ftell($fp)==fpfilesize($fp); }
?>