How can the script be modified to allow for manual deletion of directories with the necessary permissions?

To allow for manual deletion of directories with the necessary permissions, you can modify the script to include a form where users can input the directory they want to delete. Upon submission, the script will check if the user has the necessary permissions to delete the directory and then proceed with the deletion if allowed.

<?php
if(isset($_POST['directory'])){
    $directory = $_POST['directory'];
    
    if(is_dir($directory)){
        if(is_writable($directory)){
            // Delete the directory
            $success = rmdir($directory);
            
            if($success){
                echo "Directory deleted successfully.";
            } else {
                echo "Failed to delete directory.";
            }
        } else {
            echo "You do not have permission to delete this directory.";
        }
    } else {
        echo "Directory does not exist.";
    }
}
?>

<form method="post">
    <label for="directory">Directory to delete:</label>
    <input type="text" name="directory" id="directory">
    <button type="submit">Delete Directory</button>
</form>