PHP path-related dirname,realpath,__file__

Source: Internet
Author: User

? For example: The program root directory in: E:\wamp\www

1. __file__ the absolute path to the current file

Returns E:\wamp\www\index.php if called in index.php

Now look at the directory structure of the program root directory

If you call __file__ in c_system_base.php, it returns:

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

2.dirname returns the parent directory of the current directory or the directory where the current file is located (end without/)

Generally used in conjunction with __FILE__

If you call DirName (__file__) in c_system_base.php, it returns

E:\wamp\www\zb_system\function (text to return to the directory)

returns if DirName (DirName (__file__)) is called

E:\wamp\www\zb_system (directory returned to parent directory)

The Realpath () method returns the path to the absolute path or relative root of the current file

If you call Realpath (__file__) in c_system_base.php, it returns

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 relative to the program root directory

You can also use dirname with a few relative paths. /(before adding/i.e.:/.) /)

Realpath (DirName (__file__)) return E:\wamp\www\zb_system\function

Realpath (DirName (__file__). ' /.. /') return E:\wamp\www\zb_system

Realpath (DirName (__file__). ' /.. /.. /') return E:\wamp\www

PHP path-related dirname,realpath,__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.