![](/img/trans.png)
[英]PHP dir/file hierarchy with “include” and (dirname(__FILE__) . 'SOMETHING')
[英]cannot get include(dirname(__FILE__) . “/dir/file.php”); to work
好的,所以我的其中一个包含项存在问题。 我的config.php
包含一个位于类目录中的名为user.php
的文件。 如果我从其他目录调用config.php
文件,则相对路径会断开。
我尝试使用
include(dirname(__FILE__) . "/classes/user.php");
和
include __DIR__ . '../classes/user.php';
代替
include('../classes/user.php');
在我的config.php
文件中,它仍然给我一个无法文件或目录错误。 它一直在includes / classes / user.php中寻找user.php,而不是去目录。 我已经尝试使用../
和不使用斜杠的目录名方式。 似乎没有任何作用。
为了澄清,我的结构如下所示:
-admin
-classes
--user.php
-css
-drop
--index.php
-img
-includes
--config.php
-js
index.php
etc.
config.php需要使用class / user.php。 当我尝试在drop / index.php文件中包含config.php时出现问题。 它找不到类/user.php。
您是否尝试过在两个点(..)之前添加反斜杠? 像这样
include(dirname(__FILE__) . "/../classes/user.php");
只想尝试帮助您。
也许,尝试这样的事情:
include($_SERVER['SERVER_NAME'] . "/classes/user.php");
更新,如果../
和以上方法也不起作用,请尝试以下操作:
include(dirname(dirname(__FILE__)) . "/classes/user.php");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.