in PHP dirname () and __file__ is our constant, this article gives you a detailed introduction dirname () and __file__ constants in the use of some matters, a great interest of friends can enter the reference.
DirName () function
String DirName (String $path)
Gives a string containing a full path to a file, which returns the directory name after removing the file name.
In Windows, slashes (/) and backslashes () can be used as directory separators. In other environments it is a slash (/).
Example #1 dirname () example
Example
The code is as follows |
Copy Code |
Echo dirname ("c:/testweb/home.php"); Echo dirname ("/testweb/home.php"); ?> Output: C:/testweb /testweb |
__file__
The full path and file name of the file. If used in included files, returns the included file name
DirName (__file__)
__FILE__: called the PHP Magic Constant, returns the full path and file name of the currently executing PHP script, containing an absolute path
1) the dirname (__file__) function returns the path where the script is located. Update Network
For example, the file b.php contains the following content:
The code is as follows |
Copy Code |
$basedir = DirName (__file__); Echo $basedir An absolute path to the file will be printed on the page! ?> |
I did the test to get the result: e:websiteothertestcms
DirName (__file__) typically returns a directory structure of the current directory of the file to 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". Using the method tip, if you repeat one at a time you can raise the directory up one level:
For example: $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. Contains the file inclusion (DirName (__file__) that gets the top level of the directory. /.. /filename.php ');
2. How to use PHP files with HTML files
The code is as follows |
Copy Code |
if ($reguser! = "") { echo "Submit Photo "; echo "Log out"; }else{ echo "Login"; } ?> |
http://www.bkjia.com/PHPjc/445633.html www.bkjia.com true http://www.bkjia.com/PHPjc/445633.html techarticle in PHP dirname () and __file__ is our constant, this article gives you a detailed introduction dirname () and __file__ constants in the use of some matters, a great interest of friends can enter the reference. Dirn ...