Home >Backend Development >PHP Tutorial >PHP implementation code to delete all files created N minutes ago in a directory_PHP tutorial

PHP implementation code to delete all files created N minutes ago in a directory_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:58:42822browse

Copy code The code is as follows:

//delfile("upload",10);
function delfile($dir,$n) //Delete all files created N minutes ago under the DIR path;
{
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) ; ////Delete files

}
}
}
closedir($dh);
}
}
?>

http://www.bkjia.com/PHPjc/328190.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328190.htmlTechArticleCopy the code as follows: ?php //delfile("upload",10); function delfile($dir, $n) //Delete all files created N minutes ago in the DIR path; { if(is_dir($dir)) { if($dh=opendir($dir))...
Statement:
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