您好,欢迎访问一九零五行业门户网

PHP实现图片自动清理的方法_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
希望本文所述对大家的php程序设计有所帮助。
其它类似信息

推荐信息