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)
Parameter | Description |
---|---|
file | Required. Specifies the open file to truncate |
size | Required. Specifies the new file size |
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");
?>