How to get a file that's one folder above Document Root?

Issue

I have edited Apache so that my document root is here:

/var/www/html/Code/web/

But now I want to point to a file that is inside the ~/Code/ folder.

Normally I could use:

include($_SERVER['DOCUMENT_ROOT'] . '/Controllers/MyFile.php');

But that won’t work with this new document root. So, without changing my document root, how can I point back to a folder that is in this path:

/var/www/html/Code/Controller/

Solution

Use ../ to up one directory.

include($_SERVER['DOCUMENT_ROOT'] . '/../Controllers/MyFile.php');

Answered By – Al Amin Chayan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published