Find files modified not earlier than 3 days ago


/ Published in: PHP
Save to your folder(s)

Find files modified not earlier than 3 days ago


Copy this code and paste it in your HTML
  1. $files = scandir($directory);
  2.  
  3. while (list($key,$filename)=each($files)) {
  4. $files[$key] = $directory.'/'.$filename;
  5.  
  6. if ((is_dir($files[$key])) || ($filename=='.') || ($filename=='..'))
  7. unset($files[$key]);
  8. }
  9.  
  10. $recent_files = array_values(array_filter($files,'filter_by_date'));
  11.  
  12. uasort($recent_files, 'sort_by_date');
  13.  
  14. //------------------------------
  15. function filter_by_date($file) {
  16.  
  17. $three_days_ago = strtotime(date('d.m.Y'))-3*24*3600;
  18.  
  19.  
  20. if (filemtime($file)<$three_days_ago)
  21. return false;
  22.  
  23. return true;
  24. }
  25.  
  26. //----------------------------
  27. function sort_by_date($a,$b) {
  28.  
  29. return filemtime($a)-filemtime($b);
  30. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.