Home >Backend Development >PHP Tutorial >ftruncate() function in PHP
ftruncate() function truncates the open file to the specified length. The function returns TRUE on success and FALSE on failure.
ftruncate(file_pointer, size)
file_pointer - The file pointer must be open for truncation to be written.
size - The size of the file to truncate.
ftruncate() function returns.
<?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); ?>
400 50
The above is the detailed content of ftruncate() function in PHP. For more information, please follow other related articles on the PHP Chinese website!