PHP GETCWD()解决符号链接的目标,而不是当前目录 [英] php getcwd() resolving target of symlink instead of current directory

查看:571
本文介绍了PHP GETCWD()解决符号链接的目标,而不是当前目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,PHP的 GETCWD()(以及类似的功能,例如:目录名(__ FILE __))应该返回正在执行的文件的当前目录。

As far as I am aware, php's getcwd() (and similar functions eg dirname(__FILE__)) are supposed to return the current directory of the file being executed.

如果当前目录恰好是一个符号链接到另一个目录,PHP(与Apache的结合presumably)应该返回表示作为'目录'你在符号链接名称的路径。

If the current directory happens to be a symlink to another directory, php (presumably in conjunction with apache) is supposed to return the path showing the symlink name as the 'directory' you're in.

例如:

from /var/www,
directory 'one' contains index.php
symlink 'two' points at directory 'one'

one/index.php: <?php echo getcwd(); ?>

://localhost/two/index.php 在浏览器中显示的/ var / WWW /个

我希望它显示 /无功/网络/两个

有谁知道这是一个PHP或Apache设置我可以改变?或者,我无法以这种方式使用符号连接?

Does anyone know if this is a php or apache setting I can change? Or am I unable to use symlinks in this manner?

推荐答案

确定了它。使用 $ _ SERVER ['SCRIPT_FILENAME'] 如果在浏览器中。在命令行中,你可以使用获得当前符号链接目录 EXEC(PWD)

OK figured it out. Use $_SERVER['SCRIPT_FILENAME'] if over the browser. Over the command line, you can get the current symlinked directory using exec("pwd")

这篇关于PHP GETCWD()解决符号链接的目标,而不是当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆