Originally posted by Spire2000
I have been using filemtime to get the Last Modified date and time on specific files for my site. However, I would like to check the entire directory of my site in this manner but I am unsure if this is possible.
Are you looking for like a directory modified time? If so try this function, it has a argument for the directory to scan, recursive scan true/false, and just ignor the last arg, it's for the function. It will then return the latest modified time in Unix timestamp format, like time().
int dirmtime(string directory[, boolen recursive])
<?php
function dirmtime($dir, $rec=true, $mtime=0)
{
if ($dh = opendir($dir)) { // Open the dir to read..
while (($item = readdir($dh)) !== false) { // Read each item in the dir..
if (is_dir($dir.'/'.$item) && $rec && !in_array($item, array('.','..'))) { // If it's a dir and recursive is true call dirmtime().
$dmtime = dirmtime($dir.'/'.$item, $rec, $mtime); // Get the latest mtime of the dir.
$mtime = ($dmtime > $mtime ? $dmtime : $mtime); // If dir has a newer mtime set the current mtime to it.
} elseif (is_file($dir.'/'.$item)) { // If it's a file, get it's mtime.
$fmtime = filemtime($dir.'/'.$item); // Get the file mtime.
$mtime = ($fmtime > $mtime ? $fmtime : $mtime); // If the file has a newer mtime set the current mtime to it.
}
}
closedir($dh); // Close the directory handle.
} else { // If couldn't open dir, throw error and return false.
trigger_error("dirmtime() Could not open the directory to read. [{$dir}]", E_USER_WARNING);
return(false);
}
return($mtime);
}
print(date("r", dirmtime(dirname(__FILE__))));
?>