delete old files


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



Copy this code and paste it in your HTML
  1. /*! \brief delete old file in a directory
  2. * does not delete files in subdirectories
  3. * \version 1.0
  4. */
  5. $path = 'includes/tmp/';
  6.  
  7. //age in seconds
  8. $ageallowed = "1";
  9.  
  10. $directory = opendir($path);
  11. while($item = readdir($directory)){
  12. if(($item != ".") && ($item != "..")) {
  13. if(is_file($path . $item)) {
  14. if((time() - getlastmod($path . $item)) > $ageallowed) {
  15. unlink($path . $item);
  16. }
  17. }
  18. }
  19. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.