<?php
/**
* 递归实现删除目录下的所有的文件和文件夹
* @param $dir 要删除的目录
* @param bool $deleteRootToo 是否删除根目录 默认不删除
http://www.manongjc.com/article/1333.html
*/
function unlinkRecursive($dir, $deleteRootToo = false)
{
if(!$dh = @opendir($dir))
{
return;
}
while (false !== ($obj = readdir($dh)))
{
if($obj == '.' || $obj == '..')
{
continue;
}
if (!@unlink($dir . '/' . $obj))//删除文件, 如果是目录则返回false
{
unlinkRecursive($dir.'/'.$obj, true);
}
}
// http://www.manongjc.com/article/1334.html
closedir($dh);
if ($deleteRootToo)
{
@rmdir($dir);//删除目录
}
return;
}
unlinkRecursive('dir');
?>
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn