PHP getcwd()解析符号链接的目标而不是当前目录


php getcwd() resolving target of symlink instead of current directory

据我所知,php的getcwd()(和类似的函数如dirname(__FILE__))应该返回正在执行的文件的当前目录。

如果当前目录恰好是指向另一个目录的符号链接,php(可能与apache一起)应该返回显示符号链接名称的路径作为您所在的"目录"。

的例子:

from /var/www,
directory 'one' contains index.php
symlink 'two' points at directory 'one'
one/index.php: <?php echo getcwd(); ?>

在浏览器中访问http://localhost/two/index.php显示/var/www/one

我希望它显示/var/www/two

有没有人知道如果这是一个php或apache设置我可以改变?还是我无法以这种方式使用符号链接?

我明白了。在浏览器上使用$_SERVER['SCRIPT_FILENAME']。在命令行中,您可以使用exec("pwd")

获取当前的符号链接目录