Home  >  Article  >  Backend Development  >  PHP code to get the absolute path of a file (upper level directory)_PHP tutorial

PHP code to get the absolute path of a file (upper level directory)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:29:051077browse

PHP gets the absolute path of the file

Copy 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 Change 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 the images directory
chdir("images");
echo "
";
echo getcwd();
?>

Output:

C:testwebmain
C:testwebmainimages

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323471.htmlTechArticlePHP gets the absolute path of the file. The copy code is as follows: ?php echo __FILE__; // Get the absolute address of the current file, Result: D:wwwtest.php echo dirname(__FILE__); // Get the current file...
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