How can absolute paths be implemented effectively in PHP to ensure successful file deletion?

When working with file deletion in PHP, it is important to use absolute paths to ensure that the correct file is being deleted. This helps prevent accidental deletion of files due to relative path issues. To implement absolute paths effectively, you can use the `realpath()` function in PHP to get the absolute path of a file before attempting to delete it.

$filename = 'example.txt';
$absolute_path = realpath($filename);

if ($absolute_path) {
    if (unlink($absolute_path)) {
        echo "File deleted successfully.";
    } else {
        echo "Error deleting file.";
    }
} else {
    echo "File not found.";
}