note 59245 added to reserved.variables

From: Date: Wed, 30 Nov 2005 15:17:25 +0000
Subject: note 59245 added to reserved.variables
Groups: php.notes 
Request: Send a blank email to php-notes+get-99363@lists.php.net to get a copy of this message
Since $_SERVER['DOCUMENT_ROOT'] is not always present, the following will provide it where $_SERVER dosen't. <?php function resolveDocumentRoot() { $current_script = dirname($_SERVER['SCRIPT_NAME']); $current_path = dirname($_SERVER['SCRIPT_FILENAME']); /* work out how many folders we are away from document_root by working out how many folders deep we are from the url. this isn't fool proof */ $adjust = explode("/", $current_script); $adjust = count($adjust)-1; /* move up the path with ../ */ $traverse = str_repeat("../", $adjust); $adjusted_path = sprintf("%s/%s", $current_path, $traverse); /* real path expands the ../'s to the correct folder names */ return realpath($adjusted_path); } ?> It counts the number of folders down the path we are in the URL, then moves that number of folders up the current path... end result should be the document root :) It wont work with virtual folders or in any situation where the folder in the URL dosen't map to a real folder on the disk (like when using rewrites). ---- Manual Page -- http://www.php.net/manual/en/reserved.variables.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+59245 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59245&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59245&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59245&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59245&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59245&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59245&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59245&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+59245&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#99363) next »