Here's a useful PHP function I wrote for this precisely. As the original question clarifies, it returns the path from which the initial script was executed - not the file we are currently in.
/**
* Get the file path/dir from which a script/function was initially executed
*
* @param bool $include_filename include/exclude filename in the return string
* @return string
*/
function get_function_origin_path($include_filename = true) {
$bt = debug_backtrace();
array_shift($bt);
if ( array_key_exists(0, $bt) && array_key_exists('file', $bt[0]) ) {
$file_path = $bt[0]['file'];
if ( $include_filename === false ) {
$file_path = str_replace(basename($file_path), '', $file_path);
}
} else {
$file_path = null;
}
return $file_path;
}