Heim  >  Artikel  >  Backend-Entwicklung  >  php 删除目录下N分钟前创建的所有文件_PHP教程

php 删除目录下N分钟前创建的所有文件_PHP教程

WBOY
WBOYOriginal
2016-07-20 11:15:27772Durchsuche

<?<span php
</span><span /*</span><span *
* 删除当DIR路径下N分钟前创建的所有文件
* 整理:脚本学堂 www.jbxue.com
</span><span */</span>
<span //</span><span delfile("upload",10);</span>
<span function</span> delfile(<span $dir</span>,<span $n</span><span ) 
{
</span><span if</span>(<span is_dir</span>(<span $dir</span><span ))
{
</span><span if</span>(<span $dh</span>=<span opendir</span>(<span $dir</span><span ))
{
</span><span while</span> (<span false</span> !== (<span $file</span> = <span readdir</span>(<span $dh</span><span ))) 
{
</span><span if</span>(<span $file</span>!="." && <span $file</span>!=".."<span ) 
{
</span><span $fullpath</span>=<span $dir</span>."/".<span $file</span><span ;
</span><span if</span>(!<span is_dir</span>(<span $fullpath</span><span )) 
{ 
</span><span //</span><span $filedate=date("Y-m-d", filemtime($fullpath)); </span>
<span $filedate</span>=<span date</span>("Y-m-d h:i:s", <span filemtime</span>(<span $fullpath</span><span )); 
</span><span //</span><span $d1=strtotime(date("Y-m-d")); </span>
<span $d1</span>=<span strtotime</span>(<span date</span>("Y-m-d h:i:s"<span ));
</span><span $d2</span>=<span strtotime</span>(<span $filedate</span><span );
</span><span //</span><span $Days=round(($d1-$d2)/3600/24); </span>
<span $Days</span>=<span round</span>((<span $d1</span>-<span $d2</span>)/60<span ); 
</span><span if</span>(<span $Days</span>><span $n</span><span )
</span><span unlink</span>(<span $fullpath</span>); <span //</span><span //删除文件</span>
<span 
}
} 
}
}
</span><span closedir</span>(<span $dh</span><span ); 
}
}
</span>?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440200.htmlTechArticle? delfile( , ( ( ( = ( ( !== ( = ( ( !="." !=".." = ."/". (! ( = ("Y-m-d h:i:s", ( = ( ("Y-m-d h:i:s" = ( = (( - )/60 ( ( ); ( ?...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn