Initial commit.
This commit is contained in:
40
lib/php/monica/rmalldir.inc.php
Normal file
40
lib/php/monica/rmalldir.inc.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user