1<? 2//------------------------------------------------------------ 3if(!function_exists('my_filemtime')){ 4function my_filemtime($f,$recursive=false){ 5 if($recursive && is_dir($f)){ 6 $files = getFilesInDir($f, true); 7 $files[] = '.'; 8 $max = 0; 9 foreach($files as $file) 10 $max = max($max, filemtime("$f/$file")); 11 return $max; 12 } 13 return is_file($f) ? filemtime($f) : 0; 14}} 15//------------------------------------------------------------ 16if(!function_exists('getFilesInDir')){ 17function getFilesInDir($dir, $recursive=false, $type='df', $filter='', $showhidden=false, $showdots=false){ 18 //type={'d','f', else:'df'} 19 if ($dir[strlen($dir)-1]!='/') 20 $dir .= '/'; 21 $fs = array(); 22 if(!is_dir($dir)){ 23 return array(); 24 } 25 if($dh=opendir($dir)){ 26 while(($f = readdir($dh)) !== false){ 27 if ($recursive && is_dir($dir.$f) && $f!='.' && $f!='..'){ 28 $gs = getFilesInDir($dir.$f, $recursive, $type, $filter, $showhidden, $showdots); 29 foreach($gs as $g) 30 $fs[] = $f.'/'.$g; 31 } 32 if(($type=='f' && !is_file($dir.$f)) || 33 ($type=='d' && !is_dir($dir.$f)) || 34 (!$showdots && ($f=='.' || $f=='..')) || 35 (!$showhidden && $f[0]=='.') || 36 ($filter && !preg_match("/$filter/", $f)) ) 37 continue; 38 $fs[]=$f; 39 } 40 closedir($dh); 41 } 42 else 43 die("ERROR: cannot open dir"); 44 sort($fs); 45 return $fs; 46}} 47