PHP path-related dirname, realpath, FILE

Source: Internet
Author: User
The dirname, realpath, and FILE related to the PHP path, for example, the program root directory is in: E: \ wamp \ www.

1. _ FILE _ absolute path of the current FILE

If you call index. php, E: \ wamp \ www \ index. php is returned.

Next, let's look at the directory structure of the program root directory.

If _ FILE _ is called in c_system_base.php, return:

E: \ wamp \ www \ zb_system \ function \ c_system_base.php

2. dirname: returns the parent directory of the current directory or the Directory of the current file (excluding/at the end /)

Generally used in combination with _ FILE _

If you call dirname (_ FILE _) in c_system_base.php

E: \ wamp \ www \ zb_system \ function (directory where the file is returned)

If dirname (_ FILE _) is called

E: \ wamp \ www \ zb_system (the directory returns the parent directory)

The realpath () method returns the absolute path of the current file or the path relative to the root directory.

If you call realpath (_ FILE _) in c_system_base.php

E: \ wamp \ www \ zb_system \ function \ c_system_base.php

Realpath ('/') returns the disk root directory E :\

Realpath ('./') returns the root directory E: \ wamp \ www

Realpath ('../') returns the parent directory of the corresponding program root directory

It can also be used with dirname. generally, several relative paths will be added./(you need to add/before :/../)

Realpath (dirname (_ FILE _) returns E: \ wamp \ www \ zb_system \ function

Realpath (dirname (_ FILE _). '/../') returns E: \ wamp \ www \ zb_system

Realpath (dirname (_ FILE _). '/.../../') returns E: \ wamp \ www

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.