Optional include in PHP

﹥>﹥吖頭↗ 提交于 2019-12-06 14:27:47

Use the file_exists() predefined PHP function like so:

// Test if the file exists
if(file_exists('local_config.php')){
    // Include the file
    include('local_config.php');
}else{
    // Otherwise include the global config
    include('global_config.php');
}

Documentation here: http://php.net/manual/en/function.file-exists.php

you can just use file_exists()

http://php.net/manual/en/function.file-exists.php

You can use stream_resolve_include_path($filename) if you have a PHP version higher than 5.3.2

http://php.net/stream_resolve_include_path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!