Home  >  Article  >  Backend Development  >  Couplet Collection Eternal Absolute PHP Get the upper level directory of the code of the absolute path of the file

Couplet Collection Eternal Absolute PHP Get the upper level directory of the code of the absolute path of the file

WBOY
WBOYOriginal
2016-07-29 08:45:211304browse

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:
?>


chdir( ) Function
Definition and usage
chdir() function changes the current directory to the specified directory.
If successful, the function returns true, otherwise it returns false.
Syntax
chdir(directory) Parameter Description
directory Required. Specifies the new current directory.
Example

Copy code The code is as follows:


//Get the current directory
echo getcwd();
echo "
";
//Change to images directory
chdir("images");
echo "
";
echo getcwd();
?>


Output:
C:testwebmain
C:testwebmainimages

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn