PHP _ FILE _ constant

Source: Internet
Author: User
: This article mainly introduces the _ FILE _ constant of PHP. if you are interested in the PHP Tutorial, refer to it. Today I encountered the constant _ FILE _ in PHP.

I checked it online. Summarizes the following rules.

The dirname (_ FILE ___) function returns the path where the script is located.

For example, file B. php contains the following content:


If B. php is a. php file in another directoryRequireOrInclude.

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.

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)

[The reason is that the B. php file is in the default WEB directory where http. conf or PHP is used to configure the development environment.

For example, WEB_ROOT is: "C:/root/www/".]

B. php file path: "C:/root/www/B. php ".
Usage tips,

If you repeat the command, you can raise the directory to a higher level:

For example: $ d = dirname (_ FILE __));

In fact, a directory is used as a parameter to dirname (), because the last Directory returned by dirname () does not contain \ or/

Therefore, we can think that dirname () treats the bottom directory as a file name and returns the parent directory of the current directory as usual.

In this way, the directory at the upper level is obtained.

Include the files to obtain the upper-level Directory
Include(Dirname (_ FILE _). '/../filename. php ');

The above introduces the _ FILE _ constant of PHP, including The require and include content, and hopes to help those who are interested in PHP tutorials.

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: 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.