find the last modified date of a directory in php

To find the last modified date of a directory in PHP, you can use the filemtime function. This function returns the Unix timestamp of when the directory was last modified. Here's an example:

main.php
$dir_path = "/path/to/your/directory/";
$last_modified = filemtime($dir_path);
echo "Last modified: " . date("d F Y H:i:s", $last_modified);
141 chars
4 lines

In this example, we first set the $dir_path variable to the path of the directory we want to check. Then we use the filemtime function to get the last modified timestamp of the directory. Finally, we use the date function to convert the timestamp to a readable date format.

Note that filemtime only works on the directory itself, not its contents. If you want to check the last modified date of all files and sub-directories within a directory, you will need to recursively traverse the directory tree with a function like recursiveDirectoryIterator or recursiveDirectoryScan.

gistlibby LogSnag