Home >Backend Development >PHP Tutorial >ftruncate() function in PHP

ftruncate() function in PHP

WBOY
WBOYforward
2023-09-12 21:13:06826browse

ftruncate() function in PHP

ftruncate() function truncates the open file to the specified length. The function returns TRUE on success and FALSE on failure.

Syntax

ftruncate(file_pointer, size)

Parameters

  • file_pointer - The file pointer must be open for truncation to be written.

  • size - The size of the file to truncate.

Return

ftruncate() function returns.

  • TRUE if successful,
  • FALSE if failed.

Example

<?php
   echo filesize("new.txt");
   echo " ";
   $file_pointer = fopen("new.txt", "a+");
   ftruncate($file_pointer, 50);
   // close file
   fclose($file_pointer);
   // clear
   clearstatcache();
   // check file size again
   echo filesize("new.txt");
   // close file
   fclose($file_pointer);
?>

Output

400
50

The above is the detailed content of ftruncate() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete