There are many ways to get a directory in PHP, and here's how to get the current directory and relative directory using PHP.
'; Echo getcwd (), '
';//Gets the parent directory of the current file, if a.php include b.php, regardless of which file is written, is the parent directory that represents the directory where the a.php file is located, Echo Realpath ('.. '), '
'///Get the root directory of the website, all the files are in the directory where the current project is located echo $_server[' Document_root '], '
';//get directory information $path_parts = PathInfo (__file__); Echo ' dirname: ', $path _parts[' dirname '], '
'///indicates the directory where the code resides, if a.php include b.php and this code snippet is written in b.php, then get the directory where the b.php file is located echo ' basename: ', $path _parts[' basename '], '
';//Ibid., gets the file name of the file where the code is located, for example: Inc.phpecho $path _parts[' extension '], '
';//Ibid., gets the suffix name of the file where the code is located, for example: Phpecho dirname (__file__), '
';//effect with $path _parts[' dirname ')