41 lines
921 B
PHP
41 lines
921 B
PHP
<?php
|
|
// File name: rmalldir.inc.php
|
|
// Description: PHP subroutine to remove a whole directory
|
|
// Date: 2004-03-01
|
|
// Author: imacat <imacat@pristine.com.tw>
|
|
// Copyright: Copyright (C) 2004-2007 Pristine Communications
|
|
|
|
// rmalldir: Remove a whole directory
|
|
// Input: The directory $dir to be removed. It won't check at all
|
|
// Output: none
|
|
function rmalldir($dir)
|
|
{
|
|
// Non-existing
|
|
if (!file_exists($dir)) {
|
|
return;
|
|
}
|
|
// Get everything inside
|
|
$ents = array();
|
|
$dh = opendir($dir);
|
|
while (($ent = readdir($dh)) !== false) {
|
|
// Not a real entry
|
|
if ($ent == "." || $ent == "..") {
|
|
continue;
|
|
}
|
|
$ents[] = "$dir/$ent";
|
|
}
|
|
closedir($dh);
|
|
// Remove them
|
|
foreach ($ents as $ent) {
|
|
if (is_dir($ent)) {
|
|
rmalldir($ent);
|
|
} else {
|
|
unlink($ent);
|
|
}
|
|
}
|
|
rmdir($dir);
|
|
return;
|
|
}
|
|
|
|
?>
|