find the last modified date of a file in php

To find the last modified date of a file in PHP, you can use the filemtime() function. This function returns the Unix timestamp of the last modification time of the specified file.

main.php
$filename = 'path/to/file.txt';
$last_modified_time = filemtime($filename);
echo 'Last modified: ' . date('F j, Y, g:i a', $last_modified_time);
145 chars
4 lines

In the code above, we first specify the file path and name that we want to check. We then use the filemtime() function to get the Unix timestamp of the last modification time of the file. Finally, we use the date() function to format the timestamp into a human-readable format.

Note that filemtime() returns false if it fails to get the modification time of the specified file. It's also important to specify the correct path and file name of the file that you want to check.

gistlibby LogSnag