English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Filesystem Reference Manual
The ftruncate() function can truncate the opened file to the specified length and can return true on success, and false on failure.
bool ftruncate ( resource $handle , int $size )
This function can obtain a file pointer, process the file, and truncate its length to size.
<?php //Check file size echo filesize("/PhpProject/sample.txt"); echo "\n"; $file = fopen("/PhpProject/sample.txt", "a+"); ftruncate($file, 100); fclose($file); //Clear cache and check file size again clearstatcache(); echo filesize("/PhpProject/sample.txt"); ?>
Output Result
49 100