php go back one directory code example

Example 1: javascript reference file two folders up

//.. selects the parent directory from the current. Of course, this can be chained:

../../index.php
//This would be two directories up.

Example 2: how to go one folder back in __dir__ in php

dirname(__DIR__,level);
dirname(__DIR__,1);

Example 3: how to go one folder back in __dir__ in php

For PHP < 5.3 use:

$upOne = realpath(dirname(__FILE__) . '/..');
In PHP 5.3 to 5.6 use:

$upOne = realpath(__DIR__ . '/..');
In PHP >= 7.0 use:

$upOne = dirname(__DIR__, 1);

Tags:

Php Example