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);
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Learn object oriented PHP</div>
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);