For details about the difference between php getcwd and dirname (_ FILE _), getcwddirname

Source: Internet
Author: User

For details about the difference between php getcwd and dirname (_ FILE _), getcwddirname

_ FILE _ is a magic constant used to obtain the complete path and FILE name of a FILE. If it is used in a file to be included, the file name to be included is returned.

Next we will introduce the differences between getcwd and dirname (_ FILE _) through examples.

The code for file/folder/random/foo. php is as follows:

<? Phpecho getcwd (). "\ n"; echo dirname (_ FILE __). "\ n"; echo "------- \ n"; include 'bar/bar. php ';

The file/folder/random/bar. php code is as follows:

<? Phpecho getcwd (). "\ n"; echo dirname (_ FILE _). "\ n ";

Run the code/folder/random/foo. php and the result is:

/Folder/random -------/folder/random/bar

From the above example, we can see that getcwd () obtains the directory of the currently running script, regardless of whether getcwd () is in the included file or in the current execution script file, the running result will not change. _ FILE _ obtains the FILE name. If it is used in the contained FILE, it returns the included FILE name. If it is directly used in the current running script, returns the name of the file that runs the script.

I hope this article will help you. Thank you for your support!

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.