Search code examples
phpreturnparentfilepath

Get 2 levels up from dirname( __FILE__)


How can I return the pathname from the current file, only 2 directories up?

So if I my current file URL is returning theme/includes/functions.php

How can I return "theme/"

Currently I am using

return dirname(__FILE__)

Solution

  • PHP 5.3+

    return dirname(__DIR__);
    

    PHP 5.2 and lower

    return dirname(dirname(__FILE__));
    

    With PHP7 go further up the directory tree by specifying the 2nd argument to dirname. Versions prior to 7 will require further nesting of dirname.

    http://php.net/manual/en/function.dirname.php