How to get last modification time of a file in PHP

In this PHP tutorial, I am going to show you how to get last modified time of file in PHP. In many cases, it has been seen that you need to modify a file or update a file again and again. And in many situations, you need to keep track of those files modification time.

Move a file from one directory to another in PHP

In order to get the file modification time the best way is to use the inbuilt PHP function filemtime()

You can go through this documentation

But in this function, the time is returned as UNIX timestamp. So you can use date() function to get the returned time easily.

How To Delete All Files In A Directory In PHP

Get last modified time of file in PHP

For example, let’s assume that we have a file with filename myfile.txt

Now we want to get the last modification time of this text file.

The below code will show you the last modified time of the file with the date month everything.

$filename = 'myfile.txt';
if (file_exists($filename)) {
    echo "last modification time of $filename " . date ("F d Y H:i:s.", filemtime($filename));


last modification time of myfile.txt September 25 2018 08:46:11.

You may also read,

Real Time Chat Application PHP With File Transfer System AJAX

Free Currency Converter PHP using Fixer io API

3D Photo/Image Gallery (on space) Using HTML5 CSS JS

Leave a Reply

Your email address will not be published. Required fields are marked *