11

私の知る限り、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の設定で変更できるかどうかは誰にもわかりませんか? または、この方法でシンボリックリンクを使用できませんか?

4

1 に答える 1

11

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

于 2012-03-30T00:57:07.687 に答える