为什么 DOCUMENT_ROOT 与远程服务器上的 realpath('.') 不同
我
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
试试这个:
并阅读此
Try this:
And read this
您的
DOCUMENT_ROOT
中的某些目录可能实际上是符号链接到其他目录 - 引用文档,因此,如果(例如)
/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() 将始终返回前者。It could be that some of the directories in your
DOCUMENT_ROOT
are actually symlinks to other directories - to quote the documentation,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.document_root 来自您的网络服务器配置文件,这就是它与 realpath 函数不同的原因。
document_root is coming from your web server configuration file that is why is it different from realpath function.
好吧,DOCUMENT_ROOT 环境变量只是设置为错误的值。
如果您无法控制该服务器,则无法自行修复它。
要么请求支持人员修复,要么找到一种方法来避免使用此变量
,因为它看起来像 ZF 问题,我认为它很容易解决。
我从未使用过该框架,但我确信它有单个入口点或一些配置文件。
因此,您可以通过设置如下内容轻松伪造文档根:
其中“/../”表示从此类入口点到实际文档根的相对路径
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:
where '/../' represents relative path from such an entry point to the actual document root
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.