PHP how to go one level up on dirname(__FILE__)
You can use dirname(dirname(__FILE__)) to go one level up in the directory structure when using __FILE__ (which returns the current file's path).
You can use dirname(dirname(__FILE__)) to go two levels up in the directory structure when using __FILE__ (which returns the current file's path). For example:
Example of using nested dirname() to go two levels up in PHP
<?php
$current_file_path = __FILE__;
$one_level_up = dirname($current_file_path);
$two_levels_up = dirname($one_level_up);Info
Watch a video course: Learn object oriented PHP
You can also use the .. notation, or the modern dirname() depth parameter available in PHP 7+:
Example of using dirname() with a depth parameter (PHP 7+)
$two_levels_up = dirname(__FILE__, 2);