phpでの話です。
getcwd()とdirname(__FILE__)はカレントディレクトリのパスを取得するという点で同じように説明されますが、require(_once)やinclude(_once)が絡むと、全く異なった結果を返します。
実験として、次のようなファイルを作成しました。
C:/UsbWebServer/Root/phptest/getcwd.php
C:/UsbWebServer/Root/phptest/getcwd/dir/ect/ory/include.php
getcwd.phpはindex.phpをrequireしています。
getcwd.php
<?php require 'getcwd/dir/ect/ory/include.php'; ?>
include.phpには、getcwd()とdirname(__FILE__)の結果を出力する処理を書きました。
<?php echo 'getcwd() : '; var_dump(getcwd()); echo '<br />dirname(__FILE__) : '; var_dump(dirname(__FILE__)); ?>
以上の前提でgetcwd.phpを実行(ブラウザでアクセス)したところ、次のような結果になりました。
getcwd() : string(28) "C:\UsbWebServer\Root\phptest"
dirname(__FILE__) : string(47) "C:\UsbWebServer\Root\phptest\getcwd\dir\ect\ory"
上の結果をまとめると次のようになります。
getcwd()はアクセス中のファイルがあるディレクトリ
dirname(__FILE__) はそれが書かれているファイルがあるディレクトリ
トラバURL : http://suin.asia/trackback/131
氷川 XOOPS Module 開発室