What are best practices for handling file deletions in PHP to prevent errors like "No such file or directory"?

When deleting files in PHP, it is important to check if the file exists before attempting to delete it to prevent errors such as "No such file or directory". This can be done using the `file_exists()` function before calling `unlink()` to delete the file.

$file_path = 'path/to/file.txt';

if (file_exists($file_path)) {
    unlink($file_path);
    echo 'File deleted successfully';
} else {
    echo 'File does not exist';
}