Posted By

xida on 02/10/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

larste


delete old files


 / Published in: PHP
 

  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  

You need to login to post a comment.