$directory = dirname(__FILE__);
How the script works? Here __FILE__ holds the name of the currently executing file. And using finction dirname() its extracting the directory name component from it.
That means if your script name is "test.php", then __FILE__ has something like "c:\work\test.php". The function dirname() just removing that test.php from it, and returning "C:\work\"