note 8161 deleted from function.ftruncate by vincent
| From: | vincent@php.net | Date: | Sat, 16 Aug 2003 21:23:15 +0000 |
| Subject: | note 8161 deleted from function.ftruncate by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-54483@lists.php.net to get a copy of this message | ||
Note Submitter: d0hb0y@lynq.com
----
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.