PHP删除指定的目录,本代码会递归删除子目录
<?PHP
/**
* PHP删除指定的目录
*
* @param
* @author 编程之家 jb51.cc jb51.cc
* Delete a file,or a folder and its contents (recursive algorithm)
* @param string $dirname Directory to delete
* @return bool Returns TRUE on success,FALSE on failure
*/
function rmdirr($dirname)
{
// Sanity check
if (!file_exists($dirname)) {
return false;
}
// Simple delete for a file
if (is_file($dirname) || is_link($dirname)) {
return unlink($dirname);
}
// Loop through the folder
$dir = dir($dirname);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Recurse
rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
}
// Clean up
$dir->close();
return rmdir($dirname);
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528749.html