note 106293 deleted from function.getenv by danbrown
| From: | danbrown@php.net | Date: | Tue, 25 Oct 2011 23:35:47 +0000 |
| Subject: | note 106293 deleted from function.getenv by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184126@lists.php.net to get a copy of this message | ||
Note Submitter: Will Peters
----
For CLI & Web I use:
<?php
$docRoot = (PHP_SAPI == 'cli') ? substr((dirname(__FILE__).'/'), 0,
strpos((dirname(__FILE__).'/'), '/','14')) :
getenv("DOCUMENT_ROOT");
?>
It works fairly well - most of my linux servers have home directories that look like this:
/home/username/public_html
so counting the home directory and slashes is 6 chars + 8 letter username = 14. I add the extra
trailing slash for files that happen to be in the root directory all ready.