Get Root Directory Path of a PHP project Ask Question

Get Root Directory Path of a PHP project Ask Question

I have this folder structure in my PHP project. (this is as shown in eclips)

-MySystem
    +Code
    +Data_Access
    -Public_HTML
        +css
        +js
        +Templates
    -resources

When I try this code

echo $_SERVER['DOCUMENT_ROOT']

output is

D:/workspace

How can I get the path to RootDirectory of the system (MySystem), without hardcoding the Folder Name?

ベストアンサー1

For PHP >= 5.3.0 try

PHP magic constants.

__DIR__

And make your path relative.

For PHP < 5.3.0 try

dirname(__FILE__)

おすすめ記事