ftruncate()函数可以将打开的文件截断为指定的长度,并且成功时可以返回true,失败时可以返回false。
语法
bool ftruncate ( resource $handle , int $size )
该函数可以获取文件指针,处理文件并将其截断长度为 size。
在线示例
<?php
//检查文件大小
echo filesize("/PhpProject/sample.txt");
echo "\n";
$file = fopen("/PhpProject/sample.txt", "a+");
ftruncate($file, 100);
fclose($file);
//清除缓存并再次检查文件大小
clearstatcache();
echo filesize("/PhpProject/sample.txt");
?>
输出结果
49 100
PHP is_executable() PHP fopen()
展开全部