Php/func filesystem ftruncate
来自菜鸟教程
PHP ftruncate()函数
例
将打开的文件截断为指定的长度(100字节):
<?php
// Check filesize
echo filesize("test.txt");
echo "<br>";
$file = fopen("test.txt", "a+");
ftruncate($file,100);
fclose($file);
// Clear cache and check filesize again
clearstatcache();
echo filesize("test.txt");
?>
上面代码的输出将是:
792 100
定义和用法
ftruncate()函数将打开的文件截断为指定的长度。
句法
ftruncate(file, size)
参数值
| 参数 | 描述 |
|---|---|
| file | 需要。指定要截断的打开文件 |
| size | 需要。指定新文件的大小 |
技术细节
| 返回值: | 成功则为TRUE,失败则为FALSE。 |
| PHP版本: | 4.0+ |