How to use Filesystem ftruncate in PHP
In this article I am going to explain about ftruncate function in PHP.
PHP ftruncate() Function
The filesystem ftruncate function truncates a file to a given length. The function returns true on success or false on failure.
Syntax of ftruncate function
Parameters in ftruncate function
It have two parameter:
Parameter |
Description |
file |
It specifies the open file to check. |
size |
It specifies the new file size. |
Example of filesystem ftruncate function
<html>
<body>
<?php
$filename = 'C:\wamp\www\Dinesh\Mcn.txt';
$handle = fopen($filename, 'r+');
ftruncate($handle, rand(1, filesize($filename)));
rewind($handle);
echo fread($handle, filesize($filename));
fclose($handle);
?>
</body>
</html>
|
Output:
You may also want to read these related articles :here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here