This time to everyone to bring dirname (file) use case to explain, dirname (file) Use the attention of what, the following is the actual case, together to see.
File indicates that the absolute path of the currently located document includes a file name, dirname (file) represents the absolute path of the current file, and basename (file) represents the current file name, dirname (file). " /f/". basename (file) is the current file in the directory under the F directory, the filename is referred to as dirname (files), and the require represents the file to be included in the file.
Here is an explanation:
1) the dirname (file_) function returns the path where the script is located.
For example, the file b.php contains the following content:
<?php$basedir = DirName (FILE);? >
If b.php is referenced by a a.php file require or include in another directory.
The contents of the variable $basedir are also the path to the folder where the b.php resides.
Instead of becoming the directory where the a.php file resides.
2) dirname (file) typically returns the current directory of the file to a directory structure in the system root directory.
The current file name is not returned.
DirName (FILE) may also return one. (current directory)
[The reason is that the b.php file is under the default Web directory of the http.conf or PHP Configuration development environment.]
For example web_root: "c:/root/www/".
The b.php file path is: "c:/root/www/b.php".
3) Using the method tips,
If you repeat, you can raise the directory up one level:
Like what:
$d = DirName (dirname (FILE));
The fact is that a directory to dirname () to do the parameters. Because DirName () returns the final directory without \ \ or
So when you reuse it, you can think of dirname () handling the lowest-level directory as a file name. Return as usual
The parent directory of the current directory. That way, you get the top level of the directory.
4) file containing the previous level of the directory
Include (DirName (FILE). /.. /filename
PHP dirname (file) and dirname (dirname (file)) differences
DirName (DirName (FILE));
Suppose file is/home/web/config/config.php
The above method output is/home/web
DirName (dirname (file)); Gets the file on the top of the directory name
DirName (file): The name of the directory in which the files are located
script of the small note: it is actually used PHP's DirName () function and file
Definition and usage
The DirName () function returns the directory portion of the path.
Grammar
DirName (PATH)
Parameters |
Description |
Path |
Necessary. Specifies the path to check. |
Description
The path parameter is a string that contains a full path to a file. This function returns the name of the directory after the file name has been removed.
Example
<?phpecho dirname ("c:/testweb/home.php"); Echo dirname ("/testweb/home.php"); >
Output:
C:/testweb
/testweb
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
Laravel ORM on Model::find caching method
thinkphp controller variables show steps in the template