The ftruncate() function truncates an open file to the specified length.
PHP ftruncate() Function has the following syntax.
ftruncate(file,size)
Parameter | Is Required | Description |
---|---|---|
file | Required. | Open file to truncate |
size | Required. | New file size |
PHP ftruncate() Function returns TRUE on success, or FALSE on failure.
Truncates an open file to the specified length
<?php// w w w . j a v a2 s .c o m
//check filesize
echo filesize("test.txt");
echo "\n";
$file = fopen("test.txt", "a+");
ftruncate($file,100);
fclose($file);
//Clear cache and check filesize again
clearstatcache();
echo filesize("test.txt");
?>
The code above generates the following result.