The method of realizing automatic picture cleaning in PHP _php skills

Source: Internet
Author: User
Tags echo date php programming

The example in this article describes the way in which PHP implements automatic image cleanup. Share to everyone for your reference. The implementation method is as follows:

<?php/** * Image cleanup program, delete files not accessed under two weeks * * * * $sRootPath = dirname (__file__);
Define (Time_line, "-7 Day"); Delete the time when the picture was not accessed for a few days $dir = $sRootPath.
Directory_separator. ' Upload ';
$iTimeLine = Strtotime ("-7 Day");
$iTimeLine = time ();
$sHandDate = Date ("Ymd"); $sLogDir = DirName (__file__).
Directory_separator. ' Imglog '; $sLog = $sLogDir. Directory_separator. $sHandDate.
TXT ';
if (!file_exists ($sLogDir)) mkdir ($sLogDir, 0777,true);
_clearfile ($dir, $iTimeLine, $sLog); $sEnd = ' at '. \\t ". Date (" Y-m-d h:i:s ")." \\t "." EXEC over '. '
\\n ";
Echo $sEnd;
Error_log ($sEnd, 3, $sLog); /** * Clears the file operation, passing in the path where the file needs to be purged * @param unknown_type $sPath/function _clearfile ($sPath, $iTimeLine, $sLog) {if Is_dir ($sP
  Ath)) {$fp = Opendir ($sPath);
   while (!false = = ($fn = Readdir ($fp))) {if ($fn = = '. ' | | $fn = = ' ... ') continue;
   $sFilePath = $sPath. Directory_separator. $fn;
  _clearfile ($sFilePath, $iTimeLine, $sLog); }else{if ($sPath!= '. ' && $sPath!= ' ... ') {
  //. .. Files are skipped directly, not processed $iLastView = FileAtime ($sPath); if ($iLastView < $iTimeLine) {if (@unlink ($sPath) = = True) {//echo date ("y-m-d h:i:s"). '
     Successfully deleted file '. $sPath; File_put_contents ($sLog, ' Success del file: '. $sPath.
     \\n ", file_append);
     Exit $str =date ("y-m-d h:i:s"). " \\t "." Success del file: '. ' ['. $sPath. '] '. '
     \\n ";
     Error_log ($STR, 3, $sLog);
    Exit

 }}}}?>

I hope this article will help you with your PHP programming.

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.