<?php
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)); 
        $d1=strtotime(date("Y-m-d"));
        $d2=strtotime($filedate);
        $Days=round(($d1-$d2)/3600/24); 
        if($Days>$n)
        unlink($fullpath);  ////删除文件
   
         }
     }     
    }
   }
   closedir($dh);
 }
}
?>

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
  • 2021-07-09
  • 2022-01-27
猜你喜欢
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案