开发者

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

开发者 https://www.devze.com 2023-04-03 03:17 出处:网络
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.

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.

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.

Example:

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

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

Accessing http://localhost/two/index.php in a browser shows /var/www/one.

I would expect it to show /var/www/two

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


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")

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号