PHP constant DirName (__file__)

Source: Internet
Author: User
__FILE__: called the PHP Magic Constant, returns the full path and file name of the currently executing PHP script, including an absolute path.

The dirname (__file__) function returns the path where the script is located.

For example, the file index.php contains the following content:
$basedir = DirName (__file__);
Echo $basedir; An absolute path to the file will be printed on the page!
?>
I did the test to get the result: E:\wamp\www\test

If index.php is referenced by a test.php file require or include in another directory. The content of the variable $basedir is also the path to the folder where the index.php resides, rather than the directory where the test.php file resides.

DirName (DirName (__file__)); The first level of directory name is obtained.

Expand Knowledge Points:

Directory_separator:php's built-in variable directory_separator is a command that displays the system delimiter, Directory_separator is the internal constant of PHP, and does not require any definition or inclusion to be used directly.

This PHP built-in command, which returns \ on Windows and returns on Linux or Unix-like, is a common distinction that is usually used when defining a file path or uploading a saved directory.

Cases:

Phpcms Frame 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.