PHP implementation of Automatic image cleanup method,
This paper describes the method of automatic image cleaning for PHP implementation. Share to everyone for your reference. The implementation method is as follows:
<?php/** * Picture Cleanup Scheduler, delete files that are not accessed for two weeks under file */$sRootPath = dirname (__file__);//define (Time_line, "-7 Day");//delete days without visiting pictures $ 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);/** * Clear the file operation, pass in the path where the file needs to be purged * @param unknown_type $sPath */function _clearfile ($s Path, $iTimeLine, $sLog) {if (Is_dir ($sPath)) {$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 skip directly, do not process $iLastView = Fileatime ($sPath); if ($iLastView < $iTimeLine) {if (@unlink ($sPath) = = = True) {//echo date ("y-m-d h:i:s"). ' Successfully deleted files '. $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 is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1028969.html www.bkjia.com true http://www.bkjia.com/PHPjc/1028969.html techarticle PHP Implementation of Automatic image cleanup method, this article describes the implementation of PHP automatic image cleanup method. Share to everyone for your reference. The specific implementation method is as follows: php/** * Image Cleanup ...