Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP ftruncate() Function

PHP ftruncate() Function


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual


Definition and Usage

The ftruncate() function truncates an open file to a specified length.

Returns TRUE on success, FALSE on failure.

Syntax

ftruncate(file,size)

Parameters Description
file Required. Specifies the open file to truncate.
size Required. Specifies the new file size.

Example

"; $file = fopen("test.txt", "a+"); ftruncate($file,100); fclose($file); //Clear cache and check filesize again clearstatcache(); echo filesize("test.txt"); ?>

The code above will output:

792

100


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual