PHP ftruncate() Function

Definition

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

Syntax

PHP ftruncate() Function has the following syntax.

ftruncate(file,size)

Parameter

ParameterIs RequiredDescription
fileRequired.Open file to truncate
sizeRequired.New file size

Return

PHP ftruncate() Function returns TRUE on success, or FALSE on failure.

Example

Truncates an open file to the specified length


<?php//  w  ww. j  a  v a  2s .  c om
//check filesize
echo filesize("test.txt");
echo "\n";

$file = fopen("test.txt", "a+");
ftruncate($file,100);
fclose($file);

//Clear cache and check filesize again
clearstatcache();
echo filesize("test.txt");
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions