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__)
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__)
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 :)
You can simply move up a folder by using ..
.
For example:
$path = dirname(__DIR__);
$grandfatherPath = $path.'/../../';