The ftruncate() function truncates an open file to a specified length. The function returns TRUE on success, or FALSE on failure.
Syntax
ftruncate(file_pointer, size)
Parameters
file_pointer − The file pointer must be open for writing to truncate.
size − The file size to truncate to.
Return
The ftruncate() function returns.
- TRUE on success, or
- FALSE on failure.
Example
<?php
echo filesize("new.txt");
echo " ";
$file_pointer = fopen("new.txt", "a+");
ftruncate($file_pointer, 50);
// close file
fclose($file_pointer);
// clear
clearstatcache();
// check file size again
echo filesize("new.txt");
// close file
fclose($file_pointer);
?>Output
400 50