- //delfile("upload",10);
- function delfile($dir,$n) // 删除当 DIR 路径下 N 分钟前创建的所有文件;
- {
- if(is_dir($dir))
- {
- if($dh=opendir($dir))
- {
- while (false !== ($file = readdir($dh)))
- {
- if($file!="." && $file!="..")
- {
- $fullpath=$dir."/".$file;
- if(!is_dir($fullpath))
- {
- //$filedate=date("Y-m-d", filemtime($fullpath));
- $filedate=date("Y-m-d h:i:s", filemtime($fullpath));
- //$d1=strtotime(date("Y-m-d"));
- $d1=strtotime(date("Y-m-d h:i:s"));
- $d2=strtotime($filedate);
- //$Days=round(($d1-$d2)/3600/24);
- $Days=round(($d1-$d2)/60);
- if($Days>$n)
- unlink($fullpath); //// 删除文件
- }
- }
- }
- }
- closedir($dh);
- }
- }
- ?>
来源: https://www.php1.cn/detail/php-5ce1b5b730.html