简体   繁体   English

无法获取include(dirname(__ FILE__)。“ /dir/file.php”); 上班

[英]cannot get include(dirname(__FILE__) . “/dir/file.php”); to work

Okay, so I'm having an issue with one of my includes. 好的,所以我的其中一个包含项存在问题。 My config.php includes a file called user.php which is in classes directory. 我的config.php包含一个位于类目录中的名为user.php的文件。 If I call the config.php file from a different directory, relative paths get broken. 如果我从其他目录调用config.php文件,则相对路径会断开。

I tried using 我尝试使用

include(dirname(__FILE__) . "/classes/user.php");

and

include __DIR__ . '../classes/user.php'; 

instead of 代替

include('../classes/user.php');

in my config.php file and it still gives me a cannot file or directory error. 在我的config.php文件中,它仍然给我一个无法文件或目录错误。 It keeps looking for user.php in includes/classes/user.php instead of going up a directory. 它一直在includes / classes / user.php中寻找user.php,而不是去目录。 I've tried the dirname way both with ../ and without the slash. 我已经尝试使用../和不使用斜杠的目录名方式。 Nothing seems to work. 似乎没有任何作用。

To clarify, my structure looks like this: 为了澄清,我的结构如下所示:

-admin
-classes
--user.php
-css
-drop
--index.php
-img
-includes
--config.php
-js
index.php
etc.

config.php requires classes/user.php. config.php需要使用class / user.php。 I get an issue when I try to include config.php in the drop/index.php file. 当我尝试在drop / index.php文件中包含config.php时出现问题。 It can't find the classes/user.php. 它找不到类/user.php。

Do you have tried to add a backslash before two dots (..)? 您是否尝试过在两个点(..)之前添加反斜杠? Like this 像这样

include(dirname(__FILE__) . "/../classes/user.php");

Just want to try to help you. 只想尝试帮助您。

Perhaps, try something like this: 也许,尝试这样的事情:

include($_SERVER['SERVER_NAME'] . "/classes/user.php");

UPDATE, if ../ and the above doesnt work either, try this: 更新,如果../和以上方法也不起作用,请尝试以下操作:

 include(dirname(dirname(__FILE__)) . "/classes/user.php");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM