ftruncate

(PHP 4, PHP 5, PHP 7)

ftruncate锟斤拷锟侥硷拷锟截断碉拷锟斤拷锟斤拷锟侥筹拷锟斤拷

说锟斤拷

ftruncate ( resource $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($handlerand(1filesize($filename)));
rewind($handle);
echo 
fread($handlefilesize($filename));
fclose($handle);
?>

注锟斤拷

Note:

The file pointer is not changed.

锟轿硷拷

  • fopen() - 锟斤拷锟侥硷拷锟斤拷锟斤拷 URL
  • fseek() - 锟斤拷锟侥硷拷指锟斤拷锟叫讹拷位