How to catch error of require() or include() in PHP?

前端 未结 6 1038
甜味超标
甜味超标 2020-12-08 15:33

I\'m writing a script in PHP5 that requires the code of certain files. When A file is not available for inclusion, first a warning and then a fatal error are thrown. I\'d li

6条回答
  •  醉话见心
    2020-12-08 16:04

    I just use 'file_exists()':

    if (file_exists("must_have.php")) {
        require "must_have.php";
    }
    else {
        echo "Please try back in five minutes...\n";
    }
    

提交回复
热议问题