(PHP 4, PHP 5, PHP 7, PHP 8)
ftruncate — 將文件截?cái)嗟浇o定的長度
$handle, int $size): bool
接受文件指針 handle 作為參數(shù),并將文件大小截取為
size。
handle文件指針。
注意:
The
handlemust be open for writing.
sizeThe size to truncate to.
注意:
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.
成功時(shí)返回 true, 或者在失敗時(shí)返回 false。
| 版本 | 說明 |
|---|---|
| 4.3.3 |
在 PHP 4.3.3 之前,ftruncate() 在成功時(shí)返回一個(gè)
integer 值 1,而不是 boolean 的 true。
|
示例 #1 File truncation example
<?php
$filename = 'lorem_ipsum.txt';
$handle = fopen($filename, 'r+');
ftruncate($handle, rand(1, filesize($filename)));
rewind($handle);
echo fread($handle, filesize($filename));
fclose($handle);
?>
注意:
The file pointer is not changed.