PHP删除目录的内容 [英] PHP delete the contents of a directory
本文介绍了PHP删除目录的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该如何做?有没有kohana 3提供的方法?
How do I do that? Is there any method provided by kohana 3?
推荐答案
要删除一个目录和所有这些内容,你必须写一些递归删除功能 - 或使用已经存在的功能。
To delete a directory and all this content, you'll have to write some recursive deletion function -- or use one that already exists.
您可以在 rmdir ;例如,在2009年8月,由bcairns提出的建议 (引用):
You can find some examples in the user's notes on the documentation page of rmdir ; for instance, here's the one proposed by bcairns in august 2009 (quoting) :
<?php
// ensure $dir ends with a slash
function delTree($dir) {
$files = glob( $dir . '*', GLOB_MARK );
foreach( $files as $file ){
if( substr( $file, -1 ) == '/' )
delTree( $file );
else
unlink( $file );
}
rmdir( $dir );
}
?>
这篇关于PHP删除目录的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文