PHP constant dirname(__file__)
__FILE__: Known as PHP magic constant, returns the full path and file name of the currently executing PHP script, including an absolute path
1) The dirname(__FILE__) function returns the path where the script is located. Update network
For example, the file b.php tutorial contains the following content:
echo $basedir
//The absolute path to where this file is located will be printed out on the page!
?>
The test I did got the result: E:websiteothertestcms
This is equivalent to the usage of server.mappth in asp tutorial
If b.php is referenced by a.php file require or include in other directories. The content of the variable $basedir is still the path to the folder where b.php is located. Rather than becoming the directory where the a.php file is located.
2) dirname(__FILE__) generally returns a directory structure from the current directory where the file is located to the system root directory.
The current file name will not be returned. dirname(__FILE__) may also return a . (current directory) [The reason is that the b.php file is in http.conf or the default WEB directory of the PHP configuration development environment
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:
?>
===========PHP Get absolute file path========
===========chdir() function===========
The chdir() function changes the current directory to the specified directory.
If successful, the function returns true, otherwise it returns false.
Grammar
chdir(directory) parameter description
directory required. Specifies the new current directory.
Example
//Get the current directory===========chdir() function ===========echo getcwd(); echo "
chdir("images");
";
//Change to images directoryecho "
C:testwebmainimages
";
echo getcwd();
?> Output:
C:testwebmain
If successful, the function returns true, otherwise it returns false.
Grammar
chdir(directory) parameter description
directory required. Specifies the new current directory.
Example
//Get the current directoryecho getcwd(); echo "
chdir("images");
";
//Change to images directoryecho "
";
echo getcwd();
?>
http://www.bkjia.com/PHPjc/445345.html