开发者

php $_SERVER['DOCUMENT_ROOT'] too far down the tree

I have multiple sub-domains within the document_root. And multiple folders/classes within those sub-domain folders. I need something that will help me with my include_once paths, but $_SERVER[DOCUMENT_ROOT] goes too far down. And if I were to use this, and transfer the website folder later, all my include_once paths will/might break.

Hope my question is clear... Any recommendations?

Essentially, what I'm trying to do is, access classes, that are located in开发者_StackOverflow different folders, from different files. When it works for some files, it'll break in others, because of the way I'm writing the include statements.

Ie. class test{include_once '../Data/employee.php';} A file that will include the class test, will work. But say another file, from a different directory, includes the class test. It'll break. Because the other file can be 3 folders deep, instead of just one.


You can set include path per sub-domain (inside the <virtualhost>) using Apache's php_value directive.


This could solve your problem:

$relpath = "";
$tempvarrelpathdir = explode("/",dirname($SERVER['PHPSELF']));
for($i=count($tempvarrelpathdir); $i>0; $i--) if($tempvar_relpathdir[$i] != '') $relpath .= "../";

It will get the relative path to root dir...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜