How to get last modified information of a file using PHP ?
Last Updated :
22 Feb, 2021
The filemtime() function is an inbuilt function that returns the last modification of the file content. It returns as a UNIX timestamp of the last modification time of a file and returns false on failure. The filename is passed by filemtime() as a parameter. The output of this feature is cached. To clear the cache, use the clearstatcache() command.
Syntax
filemtime( filepath );
Parameter: This function accepts single parameter as mentioned above and described below:
filepath: It specifies the path to the file to check. It is required parameter.
Return Value: It returns the last time the file was modified, or false when the failure occurred. The time will be returned as a Unix timestamp that is appropriate for the date() function.
Example 1:
PHP
<?php
echo filemtime ( "gfg.txt" );
?>
|
Output: 1540211782
Example 2:
PHP
<?php
echo "Last time of file change: " .
date ( "F d Y H:i:s." , filemtime ( "gfg.txt" ));
?>
|
Output: Last time of file change: September 11 2020 09:55:51
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...