PHP ルート階層までの相対パスがほしい


・ルートディレクトリまでの相対パスを返してくれます。
 記述例)ルートディレクトリの index.html を指定したい場合
     getPathToRoot().'index.html'

・使い道は・・・あるんだろうか(笑)

-----------------------------------------------------------------------------------------

function getPathToRoot()
{
	$depth = count(explode('/', $_SERVER['SCRIPT_NAME'])) - 2;
	$path = '';
	for($i = 0; $i < $depth; $i++)
	{
		$path .= '../';
	}
	return $path;
}

-----------------------------------------------------------------------------------------

Copyright © 2008-2024 Nekorald All rights reserved.