ftruncate
ftruncate
Truncates a file to a given length
bool **ftruncate** resource $stream int $size
Takes the filepointer, , and truncates the file to
length, .
stream``size
streamThe file pointer.
Opmerking: > The must be open for writing.
stream
sizeThe size to truncate to.
Opmerking: > If is larger than the file then the file is extended with null bytes.
sizeIf is smaller than the file then the file is truncated to that size. `size`
return.success
Voorbeeld: File truncation example
<?php
$filename = 'lorem_ipsum.txt';
$handle = fopen($filename, 'r+');
ftruncate($handle, rand(1, filesize($filename)));
rewind($handle);
echo fread($handle, filesize($filename));
fclose($handle);
?>
Opmerking: > The file pointer is changed. not
fopen``fseek