php 删除目录下N分钟前创建的所有文件的实现代码

yipeiwu_com7年前PHP代码库
复制代码 代码如下:

<?php
//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);
 }
}
?>

相关文章

9个比较实用的php代码片段

比较有用的php代码片段,分享给大家供大家参考,具体代码如下 一、从网页中提取关键词 $meta = get_meta_tags('http://www.emoticode.net...

PHP stripos()函数及注意事项的分析

定义和用法stripos() 函数返回字符串在另一个字符串中第一次出现的位置。 如果没有找到该字符串,则返回 false。 语法stripos(string,find,start)...

php expects parameter 1 to be resource, array given 错误

如果你使用的是封装好的类 例如 function fetch_array($query, $result_type = MYSQL_ASSOC) { return mysql_fetch...

PHP移动文件指针ftell()、fseek()、rewind()函数总结

在对文件进行读写过程中,有时需要在文件中跳转、同不同位置读取,以及将数据写入到不同的位置。例如,使用文件模拟数据库保存数据,就需要移动文件指针。指针的位置是以从文件头开始的字节数度量的,...

php单元测试phpunit入门实例教程

本文实例讲述了php单元测试phpunit。分享给大家供大家参考,具体如下: 这篇文章提供了一些phpunit官方教程没有提到的信息,帮助初学者快速了解php单元测试,在phpunit官...