(PHP 4, PHP 5, PHP 7, PHP 8)
ftruncate — 将文件截断到指定的长度
$stream, int $size): bool
接受文件指针 stream 作为参数,并将文件大小截取为
size。
stream文件指针。
注意:
stream必须打开写入。
size截断的大小。
注意:
If
sizeis larger than the file then the file is extended with null bytes.If
sizeis smaller than the file then the file is truncated to that size.
成功时返回 true, 或者在失败时返回 false。
示例 #1 文件截取示例
<?php
$filename = 'lorem_ipsum.txt';
$handle = fopen($filename, 'r+');
ftruncate($handle, rand(1, filesize($filename)));
rewind($handle);
echo fread($handle, filesize($filename));
fclose($handle);
?>
注意:
文件指针不会改变。