PHP ftruncate() Function
Definition
The ftruncate() function truncates an open file to the specified length.
Syntax
PHP ftruncate() Function has the following syntax.
ftruncate(file,size)
Parameter
Parameter | Is Required | Description |
---|---|---|
file | Required. | Open file to truncate |
size | Required. | New file size |
Return
PHP ftruncate() Function returns TRUE on success, or FALSE on failure.
Example
Truncates an open file to the specified length
<?php// w ww. j a v a 2s . c om
//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.