PHP constant dirname (_ file __)

Source: Internet
Author: User
PHP constant dirname (_ file _) _ FILE _: a PHP magic constant. it returns the complete path and file name of the currently executed PHP script, including an absolute path.

The dirname (_ FILE _) function returns the path of the script.

For example, the index. php file contains the following content:
$ Basedir = dirname (_ FILE __);
Echo $ basedir; // The absolute path of the file is printed on the page!
?>
Test result: E: \ wamp \ www \ test

If index. php is referenced by the test. php file require or include in other directories. The content of the variable $ basedir is the path of the folder where index. php is located, rather than the directory where the test. php file is located.

Dirname (_ FILE _); the directory name at the top of the FILE is obtained.

Extended knowledge points:

DIRECTORY_SEPARATOR: the built-in variable DIRECTORY_SEPARATOR of PHP is a command for displaying system separators. DIRECTORY_SEPARATOR is an internal constant of php and can be directly used without any definition or inclusion.

This PHP built-in command returns \ on windows, and returns/on linux or unix-like, it is usually used when defining the path containing files or uploading and storing directories.

Example:

// PHPCMS framework path
Define ('PC _ path', dirname (_ FILE _). DIRECTORY_SEPARATOR );

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.