Relative root path to current directory vs. absolute root path

Posted by & filed under PHP, Windows webserver.

On a webserver you might want the path of the current directory (the directory the script is running from) but as a relative path not absolute.

Relative, eg:

/home/mydomain/

Absolute, eg:

C:\wamp\mydomain\

Try this:

$path = '/' . str_replace(array('\\',$_SERVER['DOCUMENT_ROOT']),array('/',''),__DIR__);

NB: __DIR__ is PHP 5.3 or greater. For PHP < 5.3 use dirname(__FILE__);

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Bitnami