[英]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.