Introduction
In this article I describe the PHP FileSystem functions clearstatcache, copy, dirname and disk_free_space. To learn some other filesystem functions, go to:
PHP clearstatcache() function
The PHP filesystem clearstatcache function is used to clear the cache associated with a file and this function returns no value. If you are performing multiple operations on the file use the following functions:
- stat()
- lstat()
- file_exists()
- is_writable()
- is_readable()
- is_executable()
- is_link()
- filectime()
- filegroup()
- fileowner()
- ileperms() and so on..
Then the PHP will store the cache in memory. You need to clear the cache if you are using these functions in the same PHP program multiple times and this is done with the clearstatcache() function.
Syntax
| clearstatcache() |
Example
An example of the function is:
<?php
$file=fopen("test.txt","w");
echo "<br>file-size before clearstatcache() function ..<br>";
echo filesize("test.txt");
clearstatcache();
$p="welcome to c-sharapcorner.com and This article describes how to clear the cache associated with a file.";
fwrite($file,$p);
echo "<br>file-size after clearstatcache() function ..<br>";
echo filesize("test.txt");
?>
Output
PHP copy() function
The PHP filesystem copy function will make a copy of a file that you specify on the server and the function returns true on success and false on failure.
Syntax
| copy(source_file, destination_file) |
Parameter in copy function
The parameters of the function are:
| Parameter | Description |
| source_file | It specifies the path to the source file. |
| destination_file | It specifies the destination path. |


Join the conversation! Your thoughts help the community grow.