不能包含(“absolute_path”)
我不明白为什么这行不通。
$docRoot = getenv("DOCUMENT_ROOT");
include_once($docRoot."/conn/connection.php");
include_once($docRoot."/auth/user.php");
它可以通过 wamp 在本地工作,但在我的实时服务器上无法工作。我尝试了这个:
if(!include_once($docRoot."/auth/user.php")){
session_start();
$debug = array();
$debug["docRoot"] = $docRoot;
$debug["inc_path"] = $docRoot."/auth/user.php";
$debug["file_exists"] = file_exists($debug["inc_path"]);
$_SESSION['DEBUG'] = $debug;
// exit
header("Location:debug.php");
exit();
}
调试页面只是回显该数组,它显示正确的绝对路径并表明该文件确实存在。那么为什么 include_once() 不起作用呢?服务器(MediaTemple 服务器上的 DV 帐户)根本没有配置,所以我想知道是否有 apache 或 php 设置对我造成了困扰。
最终,我想要的是一种引用文件的方式,如果我移动该文件或将其包含在另一个文件中,则不会破坏任何内容。有什么想法吗?
I can't figure out why this won't work.
$docRoot = getenv("DOCUMENT_ROOT");
include_once($docRoot."/conn/connection.php");
include_once($docRoot."/auth/user.php");
It works locally through wamp, but it won't work on my live server. I tried this:
if(!include_once($docRoot."/auth/user.php")){
session_start();
$debug = array();
$debug["docRoot"] = $docRoot;
$debug["inc_path"] = $docRoot."/auth/user.php";
$debug["file_exists"] = file_exists($debug["inc_path"]);
$_SESSION['DEBUG'] = $debug;
// exit
header("Location:debug.php");
exit();
}
The debug page just echoes that array and it shows the correct absolute paths and indicates that the file does in fact exist. So why didn't the include_once() work? The server (a DV account on a MediaTemple server) has not been configured at all, so I wonder if there is an apache or php setting that is messing with me.
Ultimately, what I want here is a way to refer to a file in such a way that if I move the file, or include it in another file, nothing will break. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在调试中,您可以尝试
is_read($docRoot."/conn/connection.php")
。即使文件没有可读权限,file_exists
函数也会返回 true。如果您收到错误代码,我们也许能够提供有关问题所在的更多信息。
In your debugging you might try
is_readable($docRoot."/conn/connection.php")
. Thefile_exists
function will return true even if the file does not have readable permissions.If you get an error code we might be able to provide more info as to what is going wrong.
打开错误报告虚拟。事实证明,另一个文件中的一个包含内容破坏了此页面,直到打开错误报告后我才能够追踪到这一点。
顺便说一句,有问题的 include 在文件路径 ( include("dir/file.ext"); ) 中缺少一个前导斜杠,它适用于我的本地 wamp 设置,但在 Linux 服务器上会中断。
Turn on error reporting dummy. It turns out one of the includes on another file was breaking this page and I wasn't able to trace that out until I turned on error reporting.
Incidentally, the problematic include was missing a leading slash in the filepath ( include("dir/file.ext"); ) which works on my local wamp setup and breaks on the linux server.