PHP filectime() Function
The PHP filectime() function returns the time when the file was last changed. This function checks for inode changes as well as regular changes.
Note: The results of this function are cached. Use clearstatcache() function to clear the cache.
Note: In most Unix filesystems, a file is considered changed when its inode data is changed; that is, when the permissions, owner, group, or other metadata from the inode is changed.
Syntax
filectime(filename)
Parameters
filename |
Required. Specify the path to the file to check. |
Return Value
Returns the time the file was last changed, or false on failure. The time is returned as a Unix timestamp, which is suitable for the date() function.
Exceptions
Upon failure, an E_WARNING is thrown.
Example:
Lets assume that we have a file called test.txt in the current working directory. The example below demonstrates on using this function to get the time when this file was last changed.
<?php $filename = 'test.txt'; //getting the time when $filename //was last changed if (file_exists($filename)) { echo "$filename was last changed: " .date("F d Y H:i:s.", filectime($filename)); } else { echo "$filename is not found."; } ?>
The output of the above code will be:
test.txt was last changed: September 01 2021 12:39:23.
❮ PHP Filesystem Reference