Raise the fooBar Rotating Header Image

php

Getting current directory in an included PHP file

I stumble upon that problem every time I do more complex PHP script includes…

Say /home/mysite/index.php includes /home/mysite/someframework/API.php. The problem is retrieving /home/mysite/someframework/ from within API.php. Since API.php isn’t called directly, all $_SERVER[] variables won’t match, they would refer to index.php.

The trick is sooo easy but just complicated enough to get me searching my sources for an occurence every time I need it. That’s why I’ll put it in my blog so I know where to find it and it may serve others the same time:

$pathToThisFile = dirname(realpath(__FILE__));