// One level up echo str_replace(realpath(dirname(__FILE__) . '/..'), '', realpath(dirname(__FILE__))); // Two levels etc. echo str_replace(realpath(dirname(__FILE__) . '/../..'), '', realpath(dirname(__FILE__)));