[thelist] PHP: specify the current directory's parent

Max Schwanekamp lists at neptunewebworks.com
Thu Apr 6 15:16:00 CDT 2006

jono at charlestonwebsolutions.com wrote:
> $settings["options"]["start_dir"]=".";
> I just need to tell ["start_dir"]="."; not to start in the current
> directory, but to start in the current directory's parent directory, which
> is the site's root.

realpath() probably will fit the bill.
$docroot = isset($_SERVER['DOCUMENT_ROOT'])
	 ? realpath($_SERVER['DOCUMENT_ROOT'])
	 : realpath('../')
$settings["options"]["start_dir"] = $docroot;
PHP as CGI on Windows doesn't set the DOCUMENT_ROOT server var, thus the 
test.  You could check for $_SERVER['PATH_TRANSLATED'] instead of 
relying on the current script's current location when DOCUMENT_ROOT is 
not set.

Max Schwanekamp

More information about the thelist mailing list