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 |
An open file can be truncated to the desired length using the ftruncate() function.
ftruncate(file, size) |
Parameter |
Description |
file |
Essential. lets you know which open file to truncate. |
size |
Essential. defines the updated file size. |
Return Value: |
If successful, TRUE; if unsuccessful, FALSE. |
PHP Version: |
4.0+ |