php 致命错误:require_once() [function.require]:需要打开失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5647075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: require_once() [function.require]: Failed opening required
提问by Gnanendra
I am working in php project, its giving the error as:
我在 php 项目中工作,它给出的错误为:
Warning:
require_once(ROOT_PATH/lib/confs/Conf.php) [function.require-once]: failed to open stream: No such file or directory in ..\htdocs\GProject\lib\exception\ExceptionHandler.php on line 20
Fatal error: require_once() [function.require]: Failed opening required 'ROOT_PATH/lib/confs/Conf.php' (include_path='.;C:\php5\pear') in ..\htdocs\GProject\lib\exception\ExceptionHandler.php on line 20
require_once(ROOT_PATH/lib/confs/Conf.php) [function.require-once]:无法打开流:第 20 行的 ..\htdocs\GProject\lib\exception\ExceptionHandler.php 中没有这样的文件或目录
致命错误:require_once() [function.require]:在 ..\htdocs\GProject\lib\ 中无法打开所需的 'ROOT_PATH/lib/confs/Conf.php' (include_path='.;C:\php5\pear')第 20 行的异常\ExceptionHandler.php
But in \ExceptionHandler.php
file, the 20th line is
但是在\ExceptionHandler.php
文件中,第 20 行是
require_once ROOT_PATH . '/lib/confs/Conf.php';
And I have the file Conf.php under the lib/confs/Conf.php
itself, even though I am getting the error.
lib/confs/Conf.php
即使我收到错误,我也有 Conf.php 文件。
What may be the problem. Thanks in advance.
可能是什么问题。提前致谢。
回答by Stephen Melrose
I would go through the following assumptions debugging this,
我会通过以下假设来调试这个,
- The file doesn't exist.
- The ROOT_PATH is incorrectly set.
- The current working directory isn't what is expected, so if ROOT_PATH is relative, it's breaking the full path.
- 该文件不存在。
- ROOT_PATH 设置不正确。
- 当前工作目录不是预期的,所以如果 ROOT_PATH 是相对的,它会破坏完整路径。
If none of the above is the case, I'm not sure.
如果以上都不是,我不确定。
Some libraries must be installed into a directory that is listed in PHP's library path. In these situations you have a few options:
某些库必须安装到 PHP 库路径中列出的目录中。在这些情况下,您有几个选择:
- Install the library into a directory searched by PHP by default (e.g., /usr/share/php).
- Update the include path using
set_include_path
without overwriting the old path (useget_include_path
in combination withPATH_SEPARATOR
).
- 将库安装到 PHP 默认搜索的目录中(例如,/usr/share/php)。
- 使用
set_include_path
而不覆盖旧路径更新包含路径(get_include_path
与 结合使用PATH_SEPARATOR
)。
回答by Shakti Singh
ROOT_PATH
is not defined in your script. This should be a defined constant with the value of your root path.
ROOT_PATH
未在您的脚本中定义。这应该是具有根路径值的定义常量。
Check it if it is defined or not.
检查它是否已定义。
if (defined('ROOT_PATH')) { echo 'Defined';} else { echo 'Not defined'; }
It is not defined.
它没有定义。
If it was defined then your error message will contain the value of defined constant since it contains the constant itself in error.
如果它已定义,那么您的错误消息将包含已定义常量的值,因为它包含错误的常量本身。
Define in your script.
在脚本中定义。
define('ROOT_PATH',$_SERVER['DOCUMENT_ROOT']); //an example
OR you have forgot to include the configuration file in which these constant are defined.
或者您忘记包含定义这些常量的配置文件。
回答by David
Just do an echo of the whole path you pass to the require_once function and carefully check if there is something wrong with it :
只需对传递给 require_once 函数的整个路径进行回显,并仔细检查它是否有问题:
echo ROOT_PATH . "/lib/confs/Conf.php";
回答by Michael
I ran into this problem today. I found the answer. PHP Bug #23392
我今天遇到了这个问题。我找到了答案。 PHP 错误 #23392
Basically you have to install the Pear OLE extension.
基本上你必须安装 Pear OLE 扩展。
pear install OLE
梨安装OLE