【发布时间】:2016-09-23 14:19:30
【问题描述】:
假设我们有一个包含以下路径的网络目录:
framework/
index.php
...
instance/
index.php -> ../framework/index.php (symlink)
...
如果我们现在请求(...)/instance/index.php,PHP 将解析符号链接并将__FILE__ 设置为(...)/framework/index.php
有没有办法解决这个问题,例如dirname(__FILE__) 会是(...)/instance?
编辑: 既然已经指出,我实际上不确定 PHP 本身是否正在解析链接或其他东西。就我而言,我使用nginx 作为网络服务器,php-fpm 作为 FastCGI。
(背景是我希望有多个引用公共代码库的 CMS 或框架实例。)
【问题讨论】:
-
你确定是 PHP 做的,而不是网络服务器?
-
没有。我只是从 php 手册中猜到:
__FILE__ The full path and filename of the file with symlinks resolved.可能这不是 php 本身完成的。 -
这解决了我的问题 [dirname($_SERVER['SCRIPT_FILENAME'])](stackoverflow.com/questions/10525880/…)