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

ftruncate() function in PHP

WBOY
Release: 2023-09-12 21:14:02
forward
803 people have browsed it

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)
Copy after login

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);
?>
Copy after login

Output

400
50
Copy after login

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

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template