- PHP 正则表达式(PCRE)
- PHP 图像处理
- PHP 5 Array 函数
- PHP 5 Calendar 函数
- PHP cURL 函数
- PHP 5 Date/Time 函数
- PHP 5 Directory 函数
- PHP Error 和 Logging 函数
- PHP 5 Filesystem 函数
- PHP Filter 函数
- PHP FTP 函数
- PHP HTTP 函数
- PHP Libxml 函数
- PHP Mail 函数
- PHP 5 Math 函数
- PHP 杂项 函数
- PHP 5 MySQLi 函数
- PHP 5 SimpleXML 函数
- PHP lcfirst() 函数
- PHP 5 String 函数
- PHP XML Parser 函数
- PHP Zip File 函数
- PHP 5 时区
PHP ftruncate() 函数
完整的 PHP Filesystem 参考手册
定义和用法
ftruncate() 函数把打开文件截断到指定的长度。
如果成功则返回 TRUE,如果失败则返回 FALSE。
语法
ftruncate(file,size)
参数 | 描述 |
---|---|
file | 必需。规定要截断的打开文件。 |
size | 必需。规定新的文件大小。 |
实例
<?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");
?>
//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
100
完整的 PHP Filesystem 参考手册
上一篇:PHP ftell() 函数
下一篇:PHP fwrite() 函数
关注微信小程序
扫描二维码
程序员编程王