Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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
  
// Checking the contents of a
// file last time changed
echo filemtime("gfg.txt");
  
?>


Output: 1540211782

Example 2:

PHP




<?php
  
// 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

Last Updated : 22 Feb, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads