If anyone can help that would be really great. Please check my code below and show me where I am going wrong.
Code: Select all
//Directory to start in
$baseDir = 'FreeSamples';
//Recursivly read files
Function listdir($start_dir='.') {
$files = array();
if (is_dir($start_dir)) {
$fh = opendir($start_dir);
while (($file = readdir($fh)) !== false) {
# loop through the files, skipping . and .., and recursing if necessary
if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue;
$filepath = $start_dir . '/' . $file;
if ( is_dir($filepath) )
$files = array_merge($files, listdir($filepath));
else
array_push($files, $filepath);
}
closedir($fh);
} else {
# false if the function was called with an invalid non-directory argument
$files = false;
}
return $files;
}
//Call the function and scan dirs
$files = listdir($baseDir);
//Make Array only files added in last week - this is not working!!
$newest_files = array();
foreach($files as $file){
$current = time();
if (($current - 60*60*24*7) < filemtime($file)){
array_push($newest_files, $file);
}
}
//Sort array so that newest is first - this is not working!!
function DateCmp($a, $b)
{
return (filemtime($a) < filemtime($b)) ? -1 : 0;
}
usort($files, 'DateCmp');
//Make it the top 10 by chopping array off
array_splice($files, 10);Thanks