how to go one folder back in dir in php

Solutions on MaxInterview for how to go one folder back in dir in php by the best coders in the world

showing results for - "how to go one folder back in dir in php"
Matteo
10 Aug 2020
1For PHP < 5.3 use:
2
3$upOne = realpath(dirname(__FILE__) . '/..');
4In PHP 5.3 to 5.6 use:
5
6$upOne = realpath(__DIR__ . '/..');
7In PHP >= 7.0 use:
8
9$upOne = dirname(__DIR__, 1);
Finn
17 Aug 2020
1// One level up
2echo str_replace(realpath(dirname(__FILE__) . '/..'), '', realpath(dirname(__FILE__)));
3
4// Two levels etc.
5echo str_replace(realpath(dirname(__FILE__) . '/../..'), '', realpath(dirname(__FILE__)));
6
Guillaume
15 Jan 2020
1dirname(__DIR__,level);
2dirname(__DIR__,1);
3