【问题标题】:php getcwd() resolving target of symlink instead of current directoryphp getcwd() 解析符号链接的目标而不是当前目录
【发布时间】:2011-11-10 07:37:52
【问题描述】:

据我所知,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 设置吗?还是我无法以这种方式使用符号链接?

【问题讨论】:

  • 你弄明白了吗?我对同样的用例感兴趣。
  • Apache 是否配置为遵循 symLinks?喜欢Options FollowSymLinks
  • 我认为这与 Apache 无关。这是一个PHP“功能”。如果你在命令行mkdir a; ln -s a b; php -r 'chdir( "b" ); echo getcwd();' 输入这个,php 会告诉你你在一个名为'a' 的目录中,即使你 chdir()ed 到'b'。

标签: php apache symlink resolve getcwd


【解决方案1】:

好的,想通了。如果通过浏览器使用$_SERVER['SCRIPT_FILENAME']。通过命令行,您可以使用 exec("pwd") 获取当前的符号链接目录

【讨论】:

    猜你喜欢
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多