First I should mention that I’ve gotten good results when using the get_cwd() function. With it, I can tell what directory I am starting from, and from there build the appropriate relative paths.
It’s simple to use.
echo getcwd();
Run the script, and you’ll know where your starting point is.
That said, beware of the register_shutdown_function(). I noticed the get_cwd() result changed while inside of this function. I found a link with a workaround, but the gist of it is that the working directory of the script can change.
http://stackoverflow.com/questions/10861606/write-to-file-with-register-shutdown-function
Here’s a sample you can use:
<?php echo "Using Dir: " . __DIR__; echo "\n\n"; echo "Using Get Current Working Directory: " . getcwd(); echo "\n\n"; echo "Using Get Include Path: " . get_include_path(); echo "\n\n"; $cwd = getcwd(); register_shutdown_function(function(){ echo "GetCWD inside of register_shutdown_function:" . getcwd(); exit(1); }); function throw_error($message) { trigger_error($message, E_USER_ERROR); exit(1); } ?>