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 and filter out HTML tags fgetss

    fgetss

    Readalinefromafilepo
  • Get file modification time filemtime

    filemtime

    Getfilemodificationt
  • Set file access and modification time touch

    touch

    Setfileaccessandmodi
  • Match file names with pattern fnmatch

    fnmatch

    Matchfilenameswithpa
  • Rewind the file pointer position rewind

    rewind

    Rewindthefilepointer
  • Read a line from a file pointer fgets

    fgets

    Readalinefromafilepo
  • Delete directory rmdir

    rmdir

    Deletedirectory
  • Determine whether the file is uploaded through HTTP POST is_uploaded_file

    is_uploaded_file

    Determinewhetherthef
Popular Articles