本篇文章主要介绍php实现清除固定日期内没有访问的图片,感兴趣的朋友参考下,希望对大家有所帮助。
本文实例讲述了php实现图片自动清理的方法,具体实现方法如下:
<?php/** * 图片清理计划程序,删除文件下两周没有访问的文件 */$srootpath = dirname(__file__);//define(time_line ,"-7 day");//删除几天没有访问图片的时间$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);/** * 清除文件操作,传入需要清除文件的路径 * @param unknown_type $spath */function _clearfile($spath, $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 != '..'){ //. ..文件直接跳过,不处理 $ilastview = fileatime($spath); if($ilastview < $itimeline){ if(@unlink($spath) === true){ //echo date("y-m-d h:i:s").'成功删除文件'.$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; } } } }}?>
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
php实现邮件发送的思路
php中存缓分类数据库缓存
php邮件发送案例
以上就是php实现清除固定日期内没有访问的图片的详细内容。