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!