Forum Moderators: coopster
I know a little about this, but not enough to get all the code i need.
Basically, I would like find all the last modification dates of all the files in a folder, and compare them to the current date. Those that have been modified in the last 7 days, I can apply a class to that file, as they're ordered in a list. Can add the <li> a special class, and obviously style it in CSS which is easy enough. Anyway, the point is the PHP side of things.
Anyway, I have a function to get the last modified date of all the files, taken from php.net:
So if its possible to work it with that, then that'd be great, but if theres an easier way to combine the 2 then that's be great. As I would like to keep the 'last file updated'.
$directory = "/dir/";
function getAllFiles($directory, $recursive = true) {
$result = array();
$handle = opendir($directory);
while ($datei = readdir($handle))
{
if (($datei != '.') && ($datei != '..'))
{
$file = $directory.$datei;
if (is_dir($file)) {
if ($recursive) {
$result = array_merge($result, getAllFiles($file.'/'));
}
} else {
$result[] = $file;
}
}
}
closedir($handle);
return $result;
}function getHighestFileTimestamp($directory, $recursive = true) {
$allFiles = getAllFiles($directory, $recursive);
$highestKnown = 0;
foreach ($allFiles as $val) {
$currentValue = filemtime($val);
if ($currentValue > $highestKnown) $highestKnown = $currentValue;
}
return $highestKnown;
}
echo 'last file updated: ';
echo date('l jS F Y', getHighestFileTimestamp('../'));
thanks :)