note 52929 added to function.fseek
| From: | alanatpeaceconstitution dot com at osu1 dot php dot net | Date: | Wed, 18 May 2005 01:03:43 +0000 |
| Subject: | note 52929 added to function.fseek | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89567@lists.php.net to get a copy of this message | ||
Thanks to Dan, whose above comment provided a key to solve the issue of how to append to a file.
After, using phpinfo(); I made sure my installation of PHP had the requisite settings mentioned
in the text to the manual entry for fopen(), I was puzzled as to why my use of fopen() with the
append option 'a' (append option) didn't work. Then I read a comment contributed to
Appendix L (http://us2.php.net/manual/en/wrappers.php) that the append option 'a' for
fopen() doesn't work as expected. The writer suggested using the 'w' option instead,
which I found did work. But the 'w' option (write option) overwrites everything in the
file.
The question remained how to accomplish appending. Following Dan's suggestion about the
'r+' option, I tried this, which works fine:
$string = "Message to write to log";
$filehandle = fopen ("/home/name/sqllogs/phpsqlerr.txt", 'r+');
fseek ( $filehandle,0, SEEK_END);
fwrite ( $filehandle, $string."\n" );
fclose ($filehandle);
----
Manual Page -- http://www.php.net/manual/en/function.fseek.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52929
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52929&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52929&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52929&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52929&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52929&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52929&report=yes
Search -- http://master.php.net/manage/user-notes.php