Home > Backend Development > PHP Tutorial > php 删除目录下N分钟前创建的所有文件的实现代码_PHP

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 12:03:21
Original
807 people have browsed it
复制代码 代码如下:
//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);
 }
}
?>
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template