What common mistakes can occur when using PHP to delete files and how can they be avoided?

One common mistake when deleting files in PHP is not checking if the file exists before attempting to delete it. This can result in errors or unexpected behavior if the file does not exist. To avoid this, you can use the `file_exists()` function to check if the file exists before attempting to delete it.

$file = 'example.txt';

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