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
  • Read a line from a file pointer fgets

    fgets

    Readalinefromafilepo
  • Modify the owner of the symbolic link lchown

    lchown

    Modifytheownerofthes
  • Change the group to which the file belongs chgrp

    chgrp

    Changethegrouptowhic
  • Establish symbolic connection symlink

    symlink

    Establishsymboliccon
  • Write data to a file file_put_contents

    file_put_contents

    Writedatatoafile
  • Test whether the file pointer reaches the end of the file feof

    feof

    Testwhetherthefilepo
  • Copy the file copy

    copy

    Copythefile
  • Close process file pointer pclose

    pclose

    Closeprocessfilepoin
Popular Articles