Current Location: Home> Function Categories> ftruncate

ftruncate

Truncate the file to a given length
Name:ftruncate
Category:File system
Programming Language:php
One-line Description:Truncate the file to the specified length.

Definition and usage

The ftruncate() function truncates the file to a specified length.

Example

 <?php
//Check file size
echo filesize ( "test.txt" ) ;
echo "<br />" ;

$file = fopen ( "test.txt" , "a+" ) ;
ftruncate ( $file , 100 ) ;
fclose ( $file ) ;

//Clear the cache and check the file size again
clearstatcache ( ) ;
echo filesize ( "test.txt" ) ;
?>

The output is similar:

 792
100

grammar

 ftruncate ( file , size )
parameter describe
file Required. Specifies that the file to be truncated is opened.
size Required. Specify the new file size.

illustrate

Accept the file pointer file as a parameter and intercept the file size as size . Return TRUE if successful, otherwise return FALSE.

Similar Functions
Popular Articles