Can you provide examples of potential pitfalls when using the unlink function in PHP?

One potential pitfall when using the unlink function in PHP is not checking if the file exists before attempting to delete it. This can result in an error being thrown if the file does not exist, disrupting the execution of the script. To avoid this issue, you can use the file_exists function to check if the file exists before calling unlink.

$file = 'example.txt';

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