为什么 DOCUMENT_ROOT 与远程服务器上的 realpath('.') 不同

发布于 2024-10-21 10:01:10 字数 1891 浏览 3 评论 0原文

echo realpath('.').'<br>';
echo dirname(__FILE__).'<br>';
echo realpath(dirname(__FILE__)).'<br>';
echo $_SERVER[PHP_SELF].'<br>'; 
echo getcwd();

总是得到

/services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain.com/public

,但在 phpinfo DOCUMENT_ROOT 中是

/services/webpages/l/i/mydomain.com/public

因为我在 .htaccess 与 Zend Framework 结合使用时遇到了困难。

在我本地,我能够使其工作。但在提供者主机上我还无法掌握其中的魔力。

EDT:我将 $_SERVER['DOCUMENT_ROOT'] = realpath($_SERVER['DOCUMENT_ROOT']); 放在索引文件上,但得到了这个。

致命错误:未捕获异常“Zend_Config_Exception”,消息为“parse_ini_file(/services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain.com/public/v0.2b/application/configs/appkeys” .ini) [function.parse-ini-file]: 无法打开流: 没有这样的文件或目录 parse_ini_file(/services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain.com/public/ v0.2b/application/configs/appkeys.ini) [function.parse-ini-file]: 无法打开流: /services2/webpages/util/i/g/gg8375620.provider.com 中没有这样的文件或目录' .br/mydomain.com/public/v0.2b/library/Zend/Config/Ini.php:181 堆栈跟踪:#0 /services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain。 com/public/v0.2b/library/Zend/Config/Ini.php(201): Zend_Config_Ini->_parseIniFile('/services2/webp...') #1 /services2/webpages/util/i/g/ gg8375620.provider.com.br/mydomain.com/public/v0.2b/library/Zend/Config/Ini.php(125):/services2/webpages/util/i/g/gg8375620.provider.com 中的 Zend_Config_。 br/mydomain.com/public/v0.2b/library/Zend/Config/Ini.php 第 181 行

EDT: 就是这样:

$appkeys = new Zend_Config_Ini(APPLICATION_PATH . '/configs/appkeys.ini');

APPLICATION_PATH 定义为

defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

with

echo realpath('.').'<br>';
echo dirname(__FILE__).'<br>';
echo realpath(dirname(__FILE__)).'<br>';
echo $_SERVER[PHP_SELF].'<br>'; 
echo getcwd();

I get always

/services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain.com/public

but in phpinfo DOCUMENT_ROOT is

/services/webpages/l/i/mydomain.com/public

because of that I'm having hard times with .htaccess in conjunction with Zend Framework.

On my local I'm able to make it work. But on the provider host I could not grasp the magic yet.

EDT: I put $_SERVER['DOCUMENT_ROOT'] = realpath($_SERVER['DOCUMENT_ROOT']); on the index file but got this.

Fatal error: Uncaught exception 'Zend_Config_Exception' with message 'parse_ini_file(/services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain.com/public/v0.2b/application/configs/appkeys.ini) [function.parse-ini-file]: failed to open stream: No such file or directory parse_ini_file(/services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain.com/public/v0.2b/application/configs/appkeys.ini) [function.parse-ini-file]: failed to open stream: No such file or directory' in /services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain.com/public/v0.2b/library/Zend/Config/Ini.php:181 Stack trace: #0 /services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain.com/public/v0.2b/library/Zend/Config/Ini.php(201): Zend_Config_Ini->_parseIniFile('/services2/webp...') #1 /services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain.com/public/v0.2b/library/Zend/Config/Ini.php(125): Zend_Config_ in /services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain.com/public/v0.2b/library/Zend/Config/Ini.php on line 181

EDT:
thats the one:

$appkeys = new Zend_Config_Ini(APPLICATION_PATH . '/configs/appkeys.ini');

and APPLICATION_PATH is defined by

defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

盛夏尉蓝 2024-10-28 10:01:10

试试这个:

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

并阅读

Try this:

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

And read this

污味仙女 2024-10-28 10:01:10

您的 DOCUMENT_ROOT 中的某些目录可能实际上是符号链接到其他目录 - 引用文档

realpath() 扩展所有符号链接并解析对输入路径中“/./”、“/../”和额外“/”字符的引用,并返回规范化的绝对​​路径名。

因此,如果(例如)/services/webpages/l 是一个目录,而 /services/webpages/l/i 是指向 / 的符号链接services2/webpages/util/i/g/gg8375620.provider.com.br,都是/services2/webpages/util/i/g/gg8375620.provider.com.br/mydomain.com/public/services/webpages/l/i/mydomain.com/public 将使您到达同一目录,但 realpath() 将始终返回前者。

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

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/
亽野灬性zι浪 2024-10-28 10:01:10

document_root 来自您的网络服务器配置文件,这就是它与 realpath 函数不同的原因。

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

独﹏钓一江月 2024-10-28 10:01:10

好吧,DOCUMENT_ROOT 环境变量只是设置为错误的值。
如果您无法控制该服务器,则无法自行修复它。
要么请求支持人员修复,要么找到一种方法来避免使用此变量

,因为它看起来像 ZF 问题,我认为它很容易解决。
我从未使用过该框架,但我确信它有单个入口点或一些配置文件。
因此,您可以通过设置如下内容轻松伪造文档根:

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

其中“/../”表示从此类入口点到实际文档根的相对路径

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

不交电费瞎发啥光 2024-10-28 10:01:10

echo realpath(dirname(FILE));

这应该会有帮助。在此链接上 http://www.tech99.us/finding-absolute- path-in-php/you 可以找到使用这些函数的详细信息。上面一行中使用的每个函数都适用于 php4 和 php5。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文