Question

I have a file which name is load.php near index.php in root folder. So i only have two files in root. I like clear works like most.

Today i needed to define directories in one file name is define.php. But it is not in root, i've added it to settings folder in root folder.

So my files:

  • index.php (requires load.php)
  • load.php (requires settings/define.php)
  • settings (includes define.php)

Now i don't know how to get root folders name?

__DIR__ in define.php gives me .../home/settings folder but i want to get root or another folders name. So what is the way?

Was it helpful?

Solution

To find out the "root" directory from inside settings/define.php, this should be sufficient:

$root = realpath(__DIR__.DIRECTORY_SEPARATOR.'..');

See it in action.

Note: the linked example uses dirname(__FILE__) instead of __DIR__ because the latter is only available on PHP >= 5.3, but is functionally equivalent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top