PHP 删除某个目录下N天前的所有文件(转)

  1. <?php  
  2. function delfile($dir,$n) //删除DIR路径下N天前创建的所有文件;  
  3. {  
  4. if(is_dir($dir))  
  5.   {  
  6.  if($dh=opendir($dir))  
  7.    {  
  8.     while (false !== ($file = readdir($dh)))   
  9.     {  
  10.      if($file!="." && $file!="..")   
  11.      {  
  12.        $fullpath=$dir."/".$file;  
  13.        if(!is_dir($fullpath))   
  14.        {              
  15.         $filedate=date("Y-m-d", filemtime($fullpath));   
  16.         $d1=strtotime(date("Y-m-d"));  
  17.         $d2=strtotime($filedate);  
  18.         $Days=round(($d1-$d2)/3600/24);   
  19.         if($Days>$n)  
  20.         unlink($fullpath);  删除文件  
  21.      
  22.          }  
  23.      }        
  24.     }  
  25.    }  
  26.    closedir($dh);   
  27.  }  
  28. }  
  29. ?>  

转载于:https://www.cnblogs.com/huojing/articles/5039038.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值