I found a great function but can't seem to be able to make it work
When I try this:
$countFile = count(glob("../dir/*.png"));
// returns number of files
However no results when I try the function:
function glob_files($source_folder, $ext, $sec, $limit){
if( !is_dir( $source_folder ) ) {
die ( "Invalid directory.\n\n" );
}
$FILES = glob($source_folder."\*.".$ext);
$set_limit = 0;
foreach($FILES as $key => $file) {
if( $set_limit == $limit ) break;
if( filemtime( $file ) > $sec ){
$FILE_LIST[$key]['path'] = substr( $file, 0, ( strrpos( $file, "\\" ) +1 ) );
$FILE_LIST[$key]['name'] = substr( $file, ( strrpos( $file, "\\" ) +1 ) );
$FILE_LIST[$key]['size'] = filesize( $file );
$FILE_LIST[$key]['date'] = date('Y-m-d G:i:s', filemtime( $file ) );
$set_limit++;
}
}
if(!empty($FILE_LIST)){
return $FILE_LIST;
} else {
die( "No files found!\n" );
}
}
$source_folder = "../dir";
$ext = "png";
$sec = "7200"; // files older than 2 hours | my files older then 2 hrs
$limit = 4;
print_r(glob_files($source_folder, $ext, $sec, $limit));
// returns No files found!