1

I know PHP > 5.3 added the Magic constants : __DIR__ to get the father dir path,

But how can I get the grandfather dir path in a smarter way?

1.__DIR__.'/../'

2.dirname(__DIR__)

AnatPort
  • 748
  • 8
  • 20
fire790620
  • 49
  • 8

2 Answers2

3

Use the second parameter levels for the dirname call

echo dirname(__DIR__,2); // 1 Level up = Father. 2 Levels up = Grandfather

However, it is not any better than what you already have. It's just smarter like you asked for :)

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
0

You can simply move up a folder by using ...

For example:

$path = dirname(__DIR__);
$grandfatherPath = $path.'/../../';
Peter
  • 8,776
  • 6
  • 62
  • 95