How PHP Gets the current directory and relative directories
There are many ways to get a directory in PHP, and here's how to get the current directory and relative directory using PHP to avoid confusing it.
<?php//gets the directory where the current file is located, if a.php include b.php no matter which file it is written in, it represents the directory where the a.php file is located echo Realpath ('. '), '; Echo getcwd (), ';// Gets the parent directory of the current file, if a.php include b.php, regardless of which file is written, represents the parent directory of the directory where the a.php file is located, Echo Realpath ('.. '), ';//Gets the Web site root directory, All files are retrieved 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 ', ';//represents 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 resides, such as: Inc.phpecho $path _parts[' extension ', ';//Ibid., gets the suffix of the file where the code resides , such as: Phpecho dirname (__file__), ';//effect with $path _parts[' dirname ']