Go One Directory Level Up/Back with Dirname() in PHP

Posted on August 26, 2019 at 2:55 pm

For PHP < 5.3 use this:

echo realpath(dirname(__FILE__) . '/..');

For PHP 5.3 to 5.6 use this:

echo realpath(__DIR__ . '/..');

For PHP >= 7.0 use this:

echo dirname(__DIR__, 1);

References:

https://www.php.net/manual/en/function.dirname.php

Receive updates via email

Other Posts

Updated Posts