risolto ora elimina sia la sottocartella e contenuto
<?php
function remove_directory($directory) {
if (!is_dir($directory)) return;
$contents = scandir($directory);
unset($contents[0], $contents[1]);
foreach($contents as $object) {
$current_object = $directory.'/'.$object;
if (filetype($current_object) === 'username') {
remove_directory($current_object);
} else {
unlink($current_object);
}
}
rmdir($directory);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['username'])) {
$username = basename($_POST['username']);
if ($username[0] != '.') remove_directory("documenti/$username");
}
?>
<form action="" method="post">
<input type="text" name="username"/>
<input type="submit" name="delete"/>
</form>