PHP implementation of Automatic image cleanup method, _php tutorial

Source: Internet
Author: User
Tags echo date

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 ...

  • 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.