Phpbench file _ get absolute file path usage. PHP constant dirname (_ file _) _ FILE __: it is called a PHP magic constant and returns the complete path and file name of the currently executed PHP script, including an absolute path 1) the PHP constant dirname (_ FILE _) returned by the dirname (_ file _) function __)
_ FILE _: a PHP magic constant. it returns the complete path and FILE name of the currently executed PHP script, including an absolute path.
1) the dirname (_ FILE _) function returns the path of the script. Update network
For example, the document B. php contains the following content:
$ Basedir = dirname (_ FILE __);
Echo $ basedir
// An absolute path of the file will be printed on the page!
?>
The result of my test is: E: websiteothertestcms.
This is equivalent to the usage of server. mappth in the asp tutorial.
If B. php is referenced by the. php file require or include in another directory. The content of the variable $ basedir is still the path of the folder where B. php is located. Instead of the directory where the. php file is located.
2) dirname (_ FILE _) usually returns a directory structure from the current directory of the FILE to the root directory of the system.
The current file name is not returned. Dirname (_ FILE _) may also return a. (current directory) [This is because the B. php FILE is in the default WEB directory where http. conf or PHP is used to configure the development environment.
Echo _ FILE _; // Obtain the absolute address of the current FILE. Result: D: wwwtest. php
Echo dirname (_ FILE _); // Obtain the absolute directory of the current FILE. Result: D: www
Echo dirname (_ FILE _); // Obtain the name of the previous Directory of the current FILE. Result: D:
?>
============ PHP obtains the absolute file path ========
=========== Chdir () function ==================
Definition and usage
The chdir () function changes the current directory to the specified directory.
If the call succeeds, the function returns true; otherwise, the function returns false.
Syntax
Chdir (directory) parameter description
Directory is required. Specifies the new current directory.
Example
// Obtain the current directory
Echo getcwd ();
Echo"
";
// Change to the images Directory
Chdir ("images ");
Echo"
";
Echo getcwd ();
?> Output:
C: testwebmain
C: testwebmainimages
=========== Chdir () function ==================
The chdir () function changes the current directory to the specified directory.
If the call succeeds, the function returns true; otherwise, the function returns false.
Syntax
Chdir (directory) parameter description
Directory is required. Specifies the new current directory.
Example
// Obtain the current directory
Echo getcwd ();
Echo"
";
// Change to the images Directory
Chdir ("images ");
Echo"
";
Echo getcwd ();
?>
Http://www.bkjia.com/PHPjc/445345.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445345.htmlTechArticlePHP constant dirname (_ file _) _ FILE _: is called PHP magic constant, returns the complete path and file name of the currently executed PHP script, contains an absolute path 1) returned by the dirname (_ FILE _) function...