PHP Get file absolute path
Copy the Code code as follows:
Echo __file__; Get the absolute address of the current file, result: D:\www\test.php
echo dirname (__file__); Get the absolute directory where the current file is located, Result: D:\www\
Echo dirname (DirName (__file__)); Gets the previous level directory name of the current file, results: D:\
?>
ChDir () function
Definition and usage
The ChDir () function changes the current directory to the specified directory.
If successful, the function returns True, otherwise false is returned.
Grammar
ChDir (directory) parameter description
Directory is required. Specifies the new current directory.
Example
Copy the Code code as follows:
Get current directory
Echo GETCWD ();
echo "
";
Change to images Directory
ChDir ("Images");
echo "
";
Echo GETCWD ();
?>
Output:
C:\testweb\main
C:\testweb\main\images
The above describes the ancient couplet encyclopedia absolute php to get the absolute path of the code on the first level of the directory, including the couplet Encyclopedia of the absolute aspects of the content, I hope that the PHP tutorial interested friends have helped.