PHP constant dirname (_ file _) method to obtain the path

Source: Internet
Author: User
_ FILE __: a PHP magic constant. it returns the complete path and FILE name of the current PHP script, including an absolute path 1) dirname (_ FILE __) the function returns the path where the script is located.

_ FILE __: a PHP magic constant. it returns the complete path and FILE name of the current PHP script, including an absolute path.

1) the dirname (_ FILE _) function returns the path where the script is located and updates the network. for example, FILE B. php contains the following content:

  1. $ Basedir = dirname (_ FILE __);
  2. Echo $ basedir
  3. // An absolute path of the file will be printed on the page!
  4. ?>

Test result: E: websiteothertestcms, which is equivalent to server in asp. mappth usage, if B. php is. if the php file require or include is referenced, the content of the variable $ basedir is still B. the path of the php folder instead of. the directory where the php file is located.

2) dirname (_ FILE _) generally returns a directory structure from the current directory of the FILE to the root directory of the system without returning the name of the current FILE, dirname (_ FILE _) may return one. (Current Directory) [The reason is B. the php file is stored in http. conf or PHP: configure the default WEB Directory for the development environment.

Several PHP "magic constants"

Description

The current row number in the _ LINE _ file.

The complete path and FILE name of The _ FILE. if it is used in the include FILE, the include FILE name will be returned, starting from PHP 4.0.2, __file _ always contains an absolute path, earlier versions sometimes contain a relative path.

_ FUNCTION name (new in PHP 4.3.0). starting from PHP 5, this constant returns the name (case sensitive) when the FUNCTION is defined ). In PHP 4, the value is always lowercase letters.

_ CLASS name (new in PHP 4.3.0). starting from PHP 5, this constant returns the name (case sensitive) when the CLASS is defined ), in PHP 4, the value is always lowercase letters.

_ METHOD _ class METHOD name (new in PHP 5.0.0), returns the name (case sensitive) when the METHOD is defined)

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.