note 89027 added to function.ftell
| From: | johnston-dot-joshua at gmail dot com | Date: | Wed, 18 Feb 2009 19:18:09 +0000 |
| Subject: | note 89027 added to function.ftell | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150812@lists.php.net to get a copy of this message | ||
RE: append-only streams
My testing shows that ftell always reports 0 when you first open a file regardless of the mode it
was opened in.
If open a file in append mode (a) and you want ftell to report the actual position in the file
instead of the position relative to where you entered you can use fseek
<?php
// create a test file with 100 bytes in it
$file = 'temp.log';
$fp = fopen($file, 'w');
fwrite($fp, str_repeat('+', 100));
fclose($fp);
// append mode to show fseek
$fp = fopen($file, 'a');
echo ftell($fp), PHP_EOL; // reports 0 even though you are at char 100
fseek($fp, 0, SEEK_END); // seek to end (does nothing on append streams)
echo ftell($fp), PHP_EOL; // reports 100
fwrite($fp, str_repeat('+', 100));
echo ftell($fp), PHP_EOL; // reports 200
?>
----
Server IP: 64.71.164.2
Probable Submitter: 64.135.71.194
----
Manual Page -- http://www.php.net/manual/en/function.ftell.php
Edit -- https://master.php.net/note/edit/89027
Del: integrated -- https://master.php.net/note/delete/89027/integrated
Del: useless -- https://master.php.net/note/delete/89027/useless
Del: bad code -- https://master.php.net/note/delete/89027/bad+code
Del: spam -- https://master.php.net/note/delete/89027/spam
Del: non-english -- https://master.php.net/note/delete/89027/non-english
Del: in docs -- https://master.php.net/note/delete/89027/in+docs
Del: other reasons-- https://master.php.net/note/delete/89027
Reject -- https://master.php.net/note/reject/89027
Search -- https://master.php.net/manage/user-notes.php