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

Source: Internet
Author: User
Tags constant lowercase php script

_ 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:
<? Php
$ 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.


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 a include file, the include file name is returned. Starting from PHP 4.0.2, __file _ always contains an absolute path, while 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 PHP 5.0.0 ). Returns the name (case sensitive) when the method is defined)

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.