I have a cache folder that stores html files. They are overwritten when needed, but a lot of the time, rarely used pages are cached in there also, that just end up using sp
By changing @pawel's solution I created function below. At first i forgot to add "path" to file name, which take my half hour to find out.
public function deleteOldFiles ($hours=24) {
$path='cache'.DS;
if ( $handle = opendir( $path ) ) {
while (false !== ($file = readdir($handle))) {
$filelastmodified = filemtime($path.$file);
if((time()-$filelastmodified) > 24*3600 && is_file($path.$file))
{
unlink($path.$file);
}
}
closedir($handle);
}
}