Dirname (_ file __)

Source: Internet
Author: User

Dirname (_ file __)
PHP defines a very useful constant, that is

_ File __

This internal constant is the complete path (path + file name) of the current PHP program ).

Even if this file is referenced by another file (include or require), __file _ is always the complete path of the file where it is located, rather than the full path of the file that references it.

See the following example:
/Home/data/demo/test/a. php

<? PHP
$ The_full_name =__ file __;
$ The_dir = dirname (_ file __);
Echo $ the_full_name; // return/home/data/demo/test/a. php
Echo $ the_dir; // return/home/data/demo/test
?>


Home/data/demo/B. php
<? PHP Include "test/a. php ";
Echo $ the_full_name; // return/home/data/demo/
Echo $ the_dir; // return/home/data/demo/test instead of/home/data/demo/
?> Test/a. php instead of/home/data/demo/B. php

Simply put:
_ File _ return current path + file name
Dirname (_ file _) returns the path of the current file path.
Dirname (_ file _); the directory name (excluding the last "/" Number) at the top of the file is obtained)

For example, if the current file is/home/data/demo/test. php
The complete path is/home/data/demo/test. php.
Dirname (_ file _) to obtain the path Section/home/data/demo (no "/" number is displayed later)

Dirname (_ file __)

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.