Retrieve the path of the parent directory.
<?php echo dirname(“c:/testweb/home.php”) . “<br />”; echo dirname(“c:/testweb/home.php”, 2) . “<br />”; echo dirname(“/testweb/home.php”); ?> |
The result of the code above will be:
c:/testweb c: /testweb |
The dirname() function returns the path to the parent directory.
dirname(path, levels) |
Parameter |
Description |
path |
Mandatory. Specifies the path to be checked. |
levels |
Optional. An integer indicating the number of parent directories to traverse. The default is 1. |
Return Value: |
The parent directory path upon success. |
PHP Version: |
4.0+ |
Binary Safe: |
Yes, in PHP 5.0 |
PHP Changelog: |
PHP 7.0 introduced the |