csmit195

PHP Recursive File Modified Check

Jan 13th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2. function latest($searchDir, array $files = array()) {
  3.     $search = opendir($searchDir);
  4.  
  5.     $dirs = array();
  6.     while($item = readdir($search)) {
  7.         if ($item == '.' || $item == '..') { continue; }
  8.         if (is_dir($searchDir.'/'.$item)) {
  9.             $dirs[] = $searchDir.'/'.$item;
  10.         }
  11.         if (is_file($searchDir.'/'.$item)) {
  12.             $ftime = filemtime($searchDir.'/'.$item);
  13.             $files[$ftime] = $searchDir.'/'.$item;
  14.         }
  15.     }
  16.     closedir($search);
  17.     if (count($dirs) > 0) {
  18.         foreach ($dirs as $dir) {
  19.             $files += latest($dir,$files);
  20.         }
  21.     }
  22.     krsort($files);
  23.     $files = array_slice($files, 0, 100, true);
  24.     return $files;
  25. }
  26. if (current_user_can( 'manage_options' )) {
  27.     foreach(latest($_SERVER['DOCUMENT_ROOT']) as $time => $file){
  28.         echo date ("F d Y H:i:s.", $time) . ': ' . $file . '</br>';
  29.     };
  30. }
  31. exit;
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment