Why DOCUMENT_ROOT is different than realpath('.') on remote server

纵然是瞬间 提交于 2019-12-06 06:08:07

Try this:

$_SERVER['DOCUMENT_ROOT'] = realpath($_SERVER['DOCUMENT_ROOT']);
echo $_SERVER['DOCUMENT_ROOT'] . "\n";

And read this

It could be that some of the directories in your DOCUMENT_ROOT are actually symlinks to other directories - to quote the documentation,

realpath() expands all symbolic links and resolves references to '/./', '/../' and extra '/' characters in the input path and return the canonicalized absolute pathname.

Therefore, if (for example), /services/webpages/l is a directory, and /services/webpages/l/i is a symlink pointing to /services2/webpages/util/i/g/gg8375620.provider.com.br, both /services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain.com/public and /services/webpages/l/i/mydomain.com/public will get you to the same directory, but realpath() will always return the former.

/services
 + webpages
 | - util
 |   - i
 |     - g 
 |       - gg8375620.provider.com.br
 |         - mydomain.com
 |           - public
 + l
   - i -> ../webpages/util/i/g/gg8375620.provider.com.br/

document_root is coming from your web server configuration file that is why is it different from realpath function.

Well, DOCUMENT_ROOT environment variable is just set to wrong value.
If you have no control of this server, you can't fix it yourself.
Either ask support to fix or find a way to avoid this variable use

As it seems as ZF problem, I think it's easy to solve.
I never used that framework but I am sure it has single entry point or some config file.
So, you can easily fake DOCUMENT ROOT by setting something like this:

$_SERVER['DOCUMENT_ROOT'] = realpath(dirname(__FILE__).'/../'); 

where '/../' represents relative path from such an entry point to the actual document root

echo realpath(dirname(FILE));

this should be helpful. on this link http://www.tech99.us/finding-absolute-path-in-php/you can find details for using these functions. each function used in above line works with php4 and php5.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!