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

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

WBOY
WBOYasal
2016-06-13 11:31:13865semak imbas

<?<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>?>
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:php单例模式的实现Artikel seterusnya:使用PHP绘制统计图