$site_files = $this->directoryToArray($site_path, TRUE);
foreach($site_files as $val){
unlink($val);
}
$site_files = $this->directoryToArray($site_path, TRUE);
krsort($site_files);
foreach($site_files as $val){
rmdir("$val");
}
rmdir("$site_path");
----------------------------------------------------------------------------------
function directoryToArray($directory, $recursive) {
$array_items = array();
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($directory . "/" . $file)) {
$file1 = $directory . "/" . $file;
$array_items[] = preg_replace("/\/\//", "/", $file1);
if ($recursive) {
$array_items = array_merge($array_items, $this->directoryToArray($directory . "/" . $file, $recursive));
}
} else {
$file = $directory . "/" . $file;
$array_items[] = preg_replace("/\/\//", "/", $file);
}
}
}
closedir($handle);
}
return $array_items;
}