【发布时间】:2013-07-01 15:03:45
【问题描述】:
我有文件 /root/update/test.php。还有一个文件,/root/connect.php;这个文件有一行
include "../config.php";
在 /root/update/test.php 中。有代码
set_include_path(".:/root");
include "connect.php";
当我运行/root/update/test.php时,它找到connect.php,但找不到config.php,给我
PHP Warning: include(../config.php): failed to open stream: No such file or directory in /root/connect.php on line 2
PHP Warning: include(): Failed opening '../config.php' for inclusion (include_path='.:/root')
这让我感到困惑,因为这些警告让我觉得我做的一切都是正确的——包含路径是 /root,它正在寻找存在的文件 ../config.php (/config.php)。有人可以帮我解决这个问题吗?请注意,由于部署到我无权访问的生产服务器,因此我不能选择使用绝对路径。
Ubuntu/Apache
【问题讨论】:
-
我尝试包含相对于您的 CWD(即 /root/update/)的 config.php,并搜索 /root/config.php
-
This: include "../config.php" 将您带到根文件夹的父文件夹。 config.php 在那里吗?
-
config.php的完整路径是什么?
-
是的,绝对路径是/config.php
-
就个人而言,我会将所有文件引用更改为绝对的,例如包括 realpath(_DIR_ . '/../') 。 '/config.php';
标签: php