问题描述
这是我的代码:
if (file_exists('config.php')) {
require('config.php'); // This is line 38
}
以某种方式产生错误:
这怎么可能?
更新:以下 工作:
if (file_exists(getcwd(). '/config.php')) {
require(getcwd(). '/config.php');
}
推荐答案
尝试忽略包含路径:
if (file_exists('config.php')) {
require('./config.php'); // This is line 38
}
如果它有效你就会丢失。目录进入包含路径,您必须选择包含它或使用相对路径文件名
if it works you are missing . directory into the include path and you have to choose to include it or using relative path file names
您可以使用php配置指令更改include_path(如果您可以更改php配置文件)或在每个文件/项目基础上使用 get_include_path()和 set_include_path()
You can change your include_path with a php configuration directive (if you can change the php config file) or resort to get_include_path() and set_include_path() on a per file/project base
例如: set_include_path('。'。PATH_SEPARATOR。get_include_path());
在你的第一行php(或公共配置文件)中;
ex: set_include_path('.'. PATH_SEPARATOR . get_include_path());
in your first line of php (or in a common configuration file);
来源:
- include php manual
- include_path
- set_include_path
- get_include_path
这篇关于即使file_exists()声明文件存在,require()也会失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!