__FILE__
is a magic constant containing the full path to the file you are executing. If you are inside an include, its path will be the contents of __FILE__
.
So with this setup:
./foo.php
<?php
echo getcwd() ,"\n";
echo dirname(__FILE__),"\n" ;
echo '-------',"\n";
include 'bar/bar.php';
./bar/bar.php
<?php
echo getcwd(),"\n";
echo dirname(__FILE__),"\n";
You get this output (Windows / Zend Studio Debugger):
C:\Users\me\Zend\workspaces\DefaultWorkspace7\random
C:\Users\me\Zend\workspaces\DefaultWorkspace7\random
-------
C:\Users\me\Zend\workspaces\DefaultWorkspace7\random
C:\Users\me\Zend\workspaces\DefaultWorkspace7\random\bar
Appearantly, getcwd
returns the directory where the file you started executing resided, while dirname(__FILE__)
is file-dependant.