Automatic image cleanup program-PHP

Source: Internet
Author: User
Automatic image cleanup program-PHP
Automatic image cleanup program-PHP

  1. /**
  2. * The Image cleanup scheduler deletes files that are not accessed for the next two weeks.
  3. */
  4. $ SRootPath = dirname (_ FILE __);
  5. // Define (TIME_LINE, "-7 day"); // delete the time when the image is not accessed for several days
  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.mongoshanddate.'.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. * To clear a file, enter the path of the file to be cleared.
  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! = '..') {//... The file is 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"). 'file deleted successfully '. $ 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. ?>

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.