(PHP 4, PHP 5, PHP 7, PHP 8)
ftruncate — 将文件截断到指定的长度
stream
文件指针。
注意:
stream
必须打开写入。
size
截断的大小。
注意:
If
size
is larger than the file then the file is extended with null bytes.If
size
is smaller than the file then the file is truncated to that size.
示例 #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);
?>
注意:
文件指针不会改变。