(PHP 4, PHP 5, PHP 7)
ftruncate — 锟斤拷锟侥硷拷锟截断碉拷锟斤拷锟斤拷锟侥筹拷锟斤拷
$handle
, int $size
) : bool
锟斤拷锟斤拷锟侥硷拷指锟斤拷 handle
锟斤拷为锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷小锟斤拷取为
size
锟斤拷
handle
锟侥硷拷指锟诫。
Note:
The
handle
must be open for writing.
size
The size to truncate to.
Note:
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.
锟缴癸拷时锟斤拷锟斤拷 TRUE
锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE
锟斤拷
锟芥本 | 说锟斤拷 |
---|---|
4.3.3 |
锟斤拷 PHP 4.3.3 之前锟斤拷ftruncate() 锟节成癸拷时锟斤拷锟斤拷一锟斤拷
integer 值 1锟斤拷锟斤拷锟斤拷锟斤拷 boolean 锟斤拷 TRUE 锟斤拷
|
Example #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);
?>
Note:
The file pointer is not changed.