Picture Auto Cleanup Program-PHP

Source: Internet
Author: User
Tags echo date
Picture Auto Cleanup Program-PHP
  1. /**
  2. * Picture Cleanup Scheduler, delete files under two weeks of no access
  3. */
  4. $sRootPath = DirName (__file__);
  5. Define (Time_line, "-7 Day"); Delete a few days without the time to access the picture
  6. $dir = $sRootPath. Directory_separator. ' Upload ';
  7. $iTimeLine = Strtotime ("-7 Day");
  8. $iTimeLine = time ();
  9. $sHandDate = Date ("Ymd");
  10. $sLogDir = DirName (__file__). Directory_separator. ' Imglog ';
  11. $sLog = $sLogDir. Directory_separator. $sHandDate. TXT ';
  12. if (!file_exists ($sLogDir)) mkdir ($sLogDir, 0777,true);
  13. _clearfile ($dir, $iTimeLine, $sLog);
  14. $sEnd = ' at '. " \\t ". Date (" Y-m-d h:i:s ")." \\t "." EXEC over '. ' \\n ";
  15. Echo $sEnd;
  16. Error_log ($sEnd, 3, $sLog);
  17. /**
  18. * Clear file operation, pass the path that need to clear the file
  19. * @param unknown_type $sPath
  20. */
  21. function _clearfile ($sPath, $iTimeLine, $sLog) {
  22. if (Is_dir ($sPath)) {
  23. $fp = Opendir ($sPath);
  24. while (!false = = ($fn = Readdir ($fp))) {
  25. if ($fn = = '. ' | | $fn = = ' ... ') continue;
  26. $sFilePath = $sPath. Directory_separator. $fn;
  27. _clearfile ($sFilePath, $iTimeLine, $sLog);
  28. }
  29. }else{
  30. if ($sPath! = '. ' && $sPath! = ' ... ') { //. .. File skipped directly, not processed
  31. $iLastView = Fileatime ($sPath);
  32. if ($iLastView < $iTimeLine) {
  33. if (@unlink ($sPath) = = = True) {
  34. echo Date ("Y-m-d h:i:s"). ' Successfully deleted files '. $sPath;
  35. File_put_contents ($sLog, ' Success del file: '. $sPath. ' \\n ", file_append);
  36. Exit
  37. $str =date ("y-m-d h:i:s"). " \\t "." Success del file: '. ' ['. $sPath. '] '. ' \\n ";
  38. Error_log ($STR, 3, $sLog);
  39. Exit
  40. }
  41. }
  42. }
  43. }
  44. }
  45. ?>
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.