note 72497 modified in function.fopen by danbrown
| From: | danbrown@php.net | Date: | Mon, 08 Jun 2009 23:36:24 +0000 |
| Subject: | note 72497 modified in function.fopen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156552@lists.php.net to get a copy of this message | ||
Note: If you have opened the file in append mode ("a" or "a+"), any data you
write to the file will always be appended, regardless of the file position. But PHP distinguish
between read and write position, and you may freely read at any position, but when you write it will
always append at the end.
If you don't want that write restriction, open the file in read-write mode ("r+") and
then start by moving the file pointer to the end.
<?php
if (($fp = fopen($filename, "r+") === FALSE) {
// handle error
exit;
}
if (fseek($fp, 0, SEEK_END) === -1) {
// handle error
exit;
}
?>
--was--
Note: If you have opened the file in append mode ("a" or "a+"), any data you
write to the file will always be appended, regardless of the file position. But PHP distinguish
between read and write position, and you may freely read at any position, but when you write it will
always append at the end.
If you don't want that write restriction, open the file in read-write mode ("r+") and
then start by moving the file pointer to the end.
if (($fp = fopen($filename, "r+") === FALSE) {
// handle error
exit;
}
if (fseek($fp, 0, SEEK_END) === -1) {
// handle error
exit;
}
http://php.net/manual/en/function.fopen.php