首頁  >  文章  >  php教程  >  php 删除目录下N分钟前创建的所有文件

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

WBOY
WBOY原創
2016-06-13 11:31:13863瀏覽

<?<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>?>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn