Phpbench file _ getting absolute file path usage _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.