How can absolute paths be used to ensure successful deletion of a directory created with incorrect permissions in PHP?

When a directory is created with incorrect permissions in PHP, it may prevent the deletion of the directory using relative paths due to permission restrictions. To ensure successful deletion, absolute paths can be used instead. Absolute paths provide the full directory path starting from the root directory, allowing PHP to access and delete the directory regardless of its permissions.

<?php
$directory = '/full/path/to/directory';
if (is_dir($directory)) {
    $files = glob($directory . '/*');
    foreach ($files as $file) {
        unlink($file);
    }
    rmdir($directory);
    echo 'Directory deleted successfully.';
} else {
    echo 'Directory does not exist.';
}
?>