PHP 删除一个目录及目录下的所有文件的函数代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

/*****
*@dir - Directory to destroy
*@virtual[optional]- whether a virtual directory
*/
function destroyDir($dir, $virtual = false)
{
$ds = DIRECTORY_SEPARATOR;
$dir = $virtual ? realpath($dir) : $dir;
$dir = substr($dir, -1) == $ds ? substr($dir, 0, -1) : $dir;
if (is_dir($dir) && $handle = opendir($dir))
{
while ($file = readdir($handle))
{
if ($file == '.' || $file == '..')
{
continue;
}
elseif (is_dir($dir.$ds.$file))
{
destroyDir($dir.$ds.$file);
}
else
{
unlink($dir.$ds.$file);
}
}
closedir($handle);
rmdir($dir);
return true;
}
else
{
return false;
}
}

相关文章

php里array_work用法实例分析

本文实例讲述了php里array_work用法。分享给大家供大家参考。具体如下: // the test array $array = array( 'php', 'array...

PHP实现的简单sha1加密功能示例

本文实例讲述了PHP实现的sha1加密功能。分享给大家供大家参考,具体如下: function encryptTokey($data){ $apikey = 'testap...

php4与php5的区别小结(配置异同)

php4 没有 静态成员 php网页后台出现这样的错误,查过SubPages1.php并没有找到相应的错误。网站在自己本地测试完全正常,传到空间以后就出现这样的错误。连验证码都看不到了,...

php获得网站访问统计信息类Compete API用法实例

本文实例讲述了php获得网站访问统计信息类Compete API用法。分享给大家供大家参考。具体如下: 这里使用php获得网站访问统计信息类Compete API,Compete是一个专...

PHP各种常见经典算法总结【排序、查找、翻转等】

本文实例讲述了PHP各种常见经典算法。分享给大家供大家参考,具体如下: 冒泡排序算法 public function test() { $arr = array(43, 54...