__FILE__: called the PHP Magic Constant, returns the full path and file name of the currently executing PHP script, including an absolute path.
The dirname (__file__) function returns the path where the script is located.
For example, the file
PHP constant dirname (_ file __)
_ File _: a PHP magic constant. It returns the complete path and file name of the currently executed PHP script, including an absolute path.
1) The dirname (_ file _) function returns the path of the script.For
"'", learning to be called "inverted quotation marks", if enclosed in "inverted quotation marks", indicating that the need to execute the command.Like ' DirName $ ', it means you need to execute dirname."" ", enclosed in double quotes, contains $
Directory management class commands for Linux commands: mkdir, rmdir, tree, DirName, basenamemkdir command: Create a new directorySyntax: mkdir [OPTION]/path/to/somewhereCommon parameter options:-P: Create parent Directory-V: Show creation
from:http://blog.163.com/wb_zhaoyuwei/blog/static/183075439201181553840490/"'", learning to be called "inverted quotation marks", if enclosed in "inverted quotation marks", indicating that the need to execute the command.Like ' DirName $ ', it means
Using DirName (__file__) is usually a very efficient way to configure file paths, but because __file__ 's path is the full path to the file (not the URL) where the current code resides, the definition profile is typically placed at the root of the
1. Understand OS. path. dirname (_ file __)
Obtain the path name:OS. path. dirname ()
Obtain the complete path of the directory where the file is located: OS. path. dirname (_ file __)
You can also configure settings. py in the django project as
I personally understand that GETCWD () will change with the inclusion file, and DirName (__file__) will not. That is , GETCWD () represents the physical path to the current execution file. such as GETCWD () shows:
/www/project/test/a.php
What is the function of PHP dirname ()?
The PHP dirname () function is the part of the directory that returns the file path. It gives a string containing a full path to a file, returning the name of the directory after removing the file name. The
Recently, when developing templates for wordpress, we found that path errors may occur when calling other php code snippets in the form of include ("file name. Previously, the server environment was always iis, and no similar bugs were found.
_ FILE __: a PHP magic constant. it returns the complete path and FILE name of the current PHP script, including an absolute path. 1) the dirname (_ FILE _) function returns the path where the script is located and updates the network, such as FILE
Found online to find a lot of articles are wrong, special verification after the hair out:DirName (__file__)PHP defines a useful constant, namely: __file__The default constant is the full path (path + filename) of the PHP program file.Even if the
Code: test
$ A = 'dir C: '; // note: the key on the left of keyboard 1 is used to output information about drive C.Echo $;
?>
Symptom: All Chinese characters after running are garbled, but they are displayed normally in the source file.
Solution:
_ FILE _: a PHP magic constant. It returns the complete path and FILE name of the currently executed PHP script, including an absolute path.1) the dirname (_ FILE _) function returns the path of the script. Update networkFor example, the document B.
Include+dirname problems
There is a sentence in a.php, include ' DirName (__file__). /1.php "'; the original meaning is to have and a.php in the same path under the 1.php to include, but in execution, the error is as follows:
PHP warning:include
$ CD ' DirName $ ' and some special usages of pwd%/* shell variables in the command line state simply execute $ CD ' DirName $ ' is meaningless. Because he returns the "." of the current path.This command, written in a script file, returns the
Man , info, help, date, Hwclock, Cal, shutdown, reboot, Halt, Poweroff, type, CD, which, DirName, BaseName, who, which, Whatis, Makewhatis, Echo, hash, TTY tac:cat display the file file in reverse order ...: View the format of the contents of the
DirName (__file__)A useful constant is defined in PHP, which is__file__The default constant is the full path (path + filename) of the current PHP program.Even if the file is referenced by another file (include or require), __file__ is always the
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.