note 8161 added to ftruncate
| From: | d0hb0y at lynq dot com | Date: | Tue, 29 Aug 2000 19:14:15 +0000 |
| Subject: | note 8161 added to ftruncate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-3616@lists.php.net to get a copy of this message | ||
I've tested this function and it appears to work correctly with 4.0.1pl2 when a file is open in
'w' mode. Here's my sample code using rewind and ftruncate on a file i've
opened and locked.
$handle=fopen($filename,"w") or die();
$canwrite = flock($handle,LOCK_EX + LOCK_NB);
if ($canwrite) {
fputs($handle,"test data xxxxxxx");
rewind($handle); /* Rewind to the top */
fputs($handle,"test");
ftruncate($handle,ftell($handle)); /* Truncate to the current position */
}
fclose($handle);
// output file will contain "test" only.
http://www.php.net/manual/function.ftruncate.php