Truncates a file to a given length
ftruncate ( resource $handle , int $size ) : bool
The file pointer.
Note: The handle must be open for writing.
The size to truncate to.
Note: If size is larger than the file then the file is extended with null bytes. If size is smaller than the file then the file is truncated to that size.
Returns TRUE on success or FALSE on failure.
<? $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/file.txt'; $mode = 'r+'; $handle = fopen($filename, $mode); echo fread($handle, filesize($filename)) . PHP_EOL; ftruncate($handle, 2); rewind($handle); echo fread($handle, filesize($filename)); fclose($handle); ?>