J_Strauton
J_Strauton

Reputation: 2418

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

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/

Upvotes: 8

Views: 7725

Answers (2)

rf1234
rf1234

Reputation: 1605

I had a similar challenge to set the path to save files and the above solution didn't work unfortunately.

I ended up using this which works fine. "dirname" returns the folder "document_root" resides in - which is one level up.

$systemPath = dirname($_SERVER['DOCUMENT_ROOT']) . '/Controllers/MyFile.php';      

Upvotes: 4

Al Amin Chayan
Al Amin Chayan

Reputation: 2500

Use ../ to up one directory.

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

Upvotes: 15

Related Questions