开发者

Finding Directory Name in other directory with PHP

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 fold开发者_StackOverflow社区er 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜