我个人理解:getcwd()会随着包含文件的改变而改变,而dirname(__FILE__)不会。即 getcwd() 表示获取当前执行文件的物理路径。
如 getcwd()显示:
/www/project/test/a.php
echo getcwd();
//echo /www/project/test
/www/project/b.php
include_once(test/a.php);
//echo /www/project而dirname(__FILE__):
/www/project/test/a.php
echo dirname(__FILE__);
//echo /www/project/test/www/project/b.php
include_once(test/a.php);
//echo /www/project/test
a.php include b.php
b.php getcwd -> a所在目录
b.php dirname(__FILE__) -> b所在目录