How to get the latest modification time of a file in php

In php, the filemtime() function can be used to obtain the latest modification time of the file. The function of this function is to obtain and return the time of the last modification of the file (in the form of timestamp), the syntax “filemtime (file path to be checked)”.

modification time of a file in php

The operating environment of this tutorial: Windows7 system, PHP7.1 version, DELL G3 computer

In php, you can use the filemtime() function to get the latest modification time of a file.

The filemtime() function returns the last modification time of the file contents; if successful, the function returns the last modification time of the file contents as a Unix timestamp. Returns FALSE on failure.


header("Content-type:text/html;charset=utf-8");
$file = "index.php";
echo "Last Modified:".filemtime($file);

Because the filemtime() function returns the modification time in the form of a timestamp, we can use the date() function to format it into a readable time format.

Let’s open the properties panel of index.phpd to see if the modification time is correct:

ok, that’s right.

Posted in: PHP

Leave a Reply

Your email address will not be published.

en_USEnglish