Andy Webb
Andy Webb

Reputation: 121

Trying to get realpath to work traversing up a directory

I was under the impression the following generate the correct path (above document root):

define('ROOT', realpath($_SERVER['DOCUMENT_ROOT'] . '../'));

CURRENT Document ROOT: /Users/SwindonWeb/Dropbox Trying to make it /Users/SwindonWeb/

I'm trying to find a script where the 1st part ($_SERVER['DOCUMENT_ROOT']) is always the same, but the second part (../) can be anything so that the ROOT can be set with a definitive path.

Any tips?

Upvotes: 0

Views: 61

Answers (1)

Andy Webb
Andy Webb

Reputation: 121

Solved the problem using:

define('ROOT', dirname(realpath($_SERVER['DOCUMENT_ROOT'] . '/Any/Other/Path/Here/')));

dirname goes up one folder from the DOCUMENT ROOT and '/Any/Other/Path/Here/' added. If you require to go up two folders just delete 'Here' and if you want to go up three, delete 'Path/Here'.

Upvotes: 1

Related Questions