PHP ftruncate() Function
In this chapter you will learn:
- Definition for PHP ftruncate() Function
- Syntax for PHP ftruncate() Function
- Parameter for PHP ftruncate() Function
- Return for PHP ftruncate() Function
- Example - truncates an open file to the specified length
Definition
The ftruncate() function truncates an open file to the specified length.
Syntax
PHP ftruncate() Function has the following syntax.
ftruncate(file,size)
Parameter
Parameter | Is Required | Description |
---|---|---|
file | Required. | Open file to truncate |
size | Required. | New file size |
Return
PHP ftruncate() Function returns TRUE on success, or FALSE on failure.
Example
Truncates an open file to the specified length
<?php// j av a2 s .c o m
//check filesize
echo filesize("test.txt");
echo "\n";
$file = fopen("test.txt", "a+");
ftruncate($file,100);
fclose($file);
//Clear cache and check filesize again
clearstatcache();
echo filesize("test.txt");
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP fwrite() Function
- Syntax for PHP fwrite() Function
- Parameter for PHP fwrite() Function
- Return for PHP fwrite() Function
- Note on PHP fwrite() Function
- Example - Write to a file
Home » PHP Tutorial » PHP File Functions