PHP ftruncate() Function

PHP fwrite() Function
PHP ftell() Function

In this article, you will learn how to remove the specific part of the file in PHP. The ftruncate() function in PHP truncates an open file to the specified length.

what is the syntax of the FTRUNCATE function in php?

ftruncate(file, size)
ParameterDescription
fileRequired. Specifies the open file to truncate
sizeRequired. Specifies the new file size
PHP ftruncate() method

examples of the FTRUNCATE function

Example 1. In this example, we truncate an open file to the specified length (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");
?>
PHP fwrite() Function
PHP ftell() Function

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top