PHP unlink() handling the exception

前端 未结 7 1098
南旧
南旧 2020-12-15 15:48

Well, I have been wondering if I can handle the unlink() function properly. I dont want the unlink() function to throw some nasty error if it is un

相关标签:
7条回答
  • 2020-12-15 16:52

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

    @unlink('your_file_name');
    

    Generally, in php, @ will surpress 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 :)

    0 讨论(0)
提交回复
热议问题