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
  • Change the group to which the file belongs chgrp

    chgrp

    Changethegrouptowhic
  • Truncate the file to a given length ftruncate

    ftruncate

    Truncatethefiletoagi
  • Create a file with a unique file name tempnam

    tempnam

    Createafilewithauniq
  • All remaining data at the output file pointer fpassthru

    fpassthru

    Allremainingdataatth
  • Returns the file name part in the path basename

    basename

    Returnsthefilenamepa
  • Write to files (safely used in binary files) fwrite

    fwrite

    Writetofiles(safelyu
  • Copy the file copy

    copy

    Copythefile
  • Get the last access time of the file fileatime

    fileatime

    Getthelastaccesstime
Popular Articles