Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

ftruncate()

Example

Reduces the length of an open file to the given value (100 bytes):

<?php
// Check filesize
echo filesize(“test.txt”);
echo “<br>”;

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

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

The following is the result of the code above:

792
100

Definition and Usage

An open file can be truncated to the desired length using the ftruncate() function.

Syntax

ftruncate(filesize)

Parameter Values

Parameter

Description

file

Essential. lets you know which open file to truncate.

size

Essential. defines the updated file size.

Technical Details

Return Value:

If successful, TRUE; if unsuccessful, FALSE.

PHP Version:

4.0+