Delete Folder/Directory Contain File Using PHP Without shell_exec


<?php
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir")
rrmdir($dir."/".$object);
else unlink ($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}

$folder = '/www/wwwroot/domain.com/folder-want-to-delete';
rmdir($folder);