Home > Article > Backend Development > Couplet Collection Eternal Absolute PHP Get the upper level directory of the code of the absolute path of the file
PHP gets the absolute path of the file
Copy the code The code is as follows:
echo __FILE__; // Get the absolute address of the current file, result: D:wwwtest.php
echo dirname(__FILE__); //Get the absolute directory where the current file is located, result: D:www
echo dirname(dirname(__FILE__)); //Get the upper directory name of the current file, result: D:
?>
Copy code The code is as follows:
//Get the current directory
echo getcwd();
echo "
";
//Change to images directory
chdir("images");
echo "
";
echo getcwd();
?>
The above introduces the upper-level directory of the code for obtaining the absolute path of the file in the Complete Collection of Couplets Eternal Absolute PHP, including the content of The Complete Collection of Couplets Eternal Absolute. I hope it will be helpful to friends who are interested in PHP tutorials.