How can absolute file paths be used to ensure proper file deletion in PHP?

When deleting files in PHP, using absolute file paths ensures that the correct file is targeted for deletion. This is important because relative paths can be ambiguous and may lead to unintended file deletions. By specifying the absolute file path, you can guarantee that the correct file is being deleted.

$file_path = '/path/to/file.txt';
if (file_exists($file_path)) {
    unlink($file_path);
    echo 'File deleted successfully.';
} else {
    echo 'File not found.';
}