Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to get last modified information of a file using PHP ?

  • Difficulty Level : Expert
  • 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.


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:


// Checking the contents of a
// file last time changed
echo filemtime("gfg.txt");
Output: 1540211782

Example 2:


// A file's last modification time as a
// date that is in human-readable form
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
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!