【发布时间】:2012-07-03 10:04:36
【问题描述】:
我尝试创建一个引导文件,但每当我尝试在另一个文件中包含或要求它时,就会不断出现这样的错误:
警告: require_once(../folder/file.php) [function.require-once]:无法打开流:没有这样的文件或目录...
致命错误: require_once() [function.require]: 无法打开所需的 '../folder/file.php' (include_path='.:') in...
绘制整个场景: 我有一个引导文件 load.php。在其中,我连接到位于 ../config/config.php 的配置文件。在加载文件上方,我在 classes/database.php 中有一个数据库类文件。在数据库文件中,我写了这个 if 语句:
if ( file_exists('../load.php') ) {
echo 'load.php: It exists';
require_once('../load.php');
} else {
echo 'load.php: It does not exist';
}
在加载文件中,我写了一个类似的 if 语句,但检查配置文件是否存在。令人惊讶的是,当我加载 database.php 文件时,我得到:
load.php: It exists
config.php: file doesn't exist
但是当我加载 load.php 文件时,我得到:
config.php: It exists
这是我的文件所在的位置:
根目录: /Library/WebServer/Documents/project
config.php 文件 /Library/WebServer/Documents/project/config/config.php
load.php 文件: /Library/WebServer/Documents/project/includes/load.php
database.php 文件: /Library/WebServer/Documents/project/includes/classes/database.php
我需要有关此错误的帮助。 谢谢,
【问题讨论】:
-
我很难跟上。您可以发布您的完整代码并截取文件结构的屏幕截图或 ascii-art 吗?这将使每个人的事情变得更容易。
-
您正在使用文件的相对路径。您能否解释一下这些文件所在位置的文件结构...这将有助于解释此错误。
-
仔细检查您的路径。另外,这是从哪里来的
config.php: file doesn't exist? -
如果
bootstrap目录中有 load.php 和 config.php。那么你应该注意相对路径... -
我在主帖底部包含了我的文件路径。
标签: php include directory require