note 62926 added to function.filesize
| From: | mkamerma at science dot uva dot nl | Date: | Sun, 12 Mar 2006 14:12:23 +0000 |
| Subject: | note 62926 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-105372@lists.php.net to get a copy of this message | ||
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); }
?>
----
Server IP: 194.109.193.119
Probable Submitter: 80.61.35.236
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.filesize.php
Edit -- http://master.php.net/note/edit/62926
Del: integrated -- http://master.php.net/note/delete/62926/integrated
Del: useless -- http://master.php.net/note/delete/62926/useless
Del: bad code -- http://master.php.net/note/delete/62926/bad+code
Del: spam -- http://master.php.net/note/delete/62926/spam
Del: non-english -- http://master.php.net/note/delete/62926/non-english
Del: in docs -- http://master.php.net/note/delete/62926/in+docs
Del: other reasons-- http://master.php.net/note/delete/62926
Reject -- http://master.php.net/note/reject/62926
Search -- http://master.php.net/manage/user-notes.php