PHP unlink() handling the exception

NOTE: This probably won’t work any longer. See Brian’s comment

If you want to only suppress the error, you can do this:

@unlink('your_file_name');

Generally, in PHP, @ will suppress any error.

The better way is minimize the error probability. You’ve say that one of error possibility is caused by non-exist file. If I were you, I’ll do this:

if(file_exists('your_file_name')){
    unlink('your_file_name');
}else{
    echo 'file not found';
}

Good luck 🙂

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)