0

即使使用多个查找文件,我也无法找到../该文件:

root -> public -> secure -> lock  -> login / "data.php"
                            panel -> data -> list / "list.php"

我想包含data.php我的list.php并尝试执行以下操作来包含数据:

include("../../../../lock/login/data.php");
include("../../../lock/login/data.php");
and also
include("../../lock/login/data.php");

但是,这似乎不起作用,但是如果我将它放在旁边list.php并执行以下操作,它会很好地读取数据:

include("data.php");

我的代码做错了什么,执行此操作的更好方法是什么?

4

2 回答 2

2

学习使用

__FILE__; // for your current file path
dirname(__FILE__) or __DIR__; // for your current file parent folder
$_SERVER['DOCUMENT_ROOT']; // for your sites inception folder, your pivotal point

这应该让你上路。然后你可以

include __DIR__.'/../file-REALLY-relative-to-directory-of-edit-file.php';
include $_SERVER['DOCUMENT_ROOT'].'/absolute-path-reliable-for-your-site.php';

永远不要做 RELATIVE INCLUDES LIKE (当前目录可以改变和破坏你的世界)

include 'an-unreliable-NOT-REALLY-relative-file.php';

希望能帮助到你!

于 2012-10-21T17:19:13.587 回答
1

请改用 phpsinclude_path功能并指定那些包含要包含的 php 脚本的目录。更轻松、更安全。

于 2012-10-21T16:39:25.887 回答