开发者

can't include("absolute_path")

开发者 https://www.devze.com 2023-02-10 01:21 出处:网络
I can\'t figure out why this won\'t work. $docRoot = getenv(\"DOCUMENT_ROOT\"); include_once($docRoot.\"/conn/connection.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["f开发者_如何转开发ile_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?


In your debugging you might try is_readable($docRoot."/conn/connection.php"). The file_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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消