What are the best practices for handling file deletion in PHP?

When deleting files in PHP, it is important to first check if the file exists before attempting to delete it to avoid errors. Additionally, it is recommended to use the `unlink()` function to delete files as it is a built-in PHP function specifically designed for this purpose. Lastly, always make sure to handle any potential errors or exceptions that may occur during the deletion process.

// Check if the file exists before attempting to delete it
$file_path = 'path/to/file.txt';
if (file_exists($file_path)) {
    // Delete the file using the unlink() function
    if (unlink($file_path)) {
        echo 'File deleted successfully';
    } else {
        echo 'Error deleting file';
    }
} else {
    echo 'File does not exist';
}