Size of /tmp/trunc-test.txt before: 0 bytes.
Size of /tmp/trunc-test.txt after: 0 bytes.
<?php
// http://www.pgregg.com/projects/php/code/ftruncate.php
$chartrunclen = 10;
$file = '/tmp/trunc-test.txt';
$fsize = filesize($file);
echo '<br>Size of ', $file, ' before: ', $fsize, ' bytes.', "\n";
$fp = fopen($file, 'ab');
if ($fp === false) exit;
ftruncate($fp, max($fsize - $chartrunclen, 0));
fclose($fp); // close the file
clearstatcache();
$fsize2 = filesize($file);
echo '<br>Size of ', $file, ' after: ', $fsize2, ' bytes.', "\n<br>";
highlight_file(__FILE__);
?>