__file__ constants and DirName () instance usage in PHP

Source: Internet
Author: User
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.
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".

Using the method tips,
If you repeat, 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.

Files that contain the previous level of the directory

Include (DirName (FILE). ' /.. /filename.php ');

2. How to use PHP files with HTML files

<?PHPIF ($reguser! = "") {   echo "Submit Photo";   echo "Log out"; }else{   echo "Login";}?>

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.

The

1) dirname (file_) function returns the path where the script is located.
For example, file b.php contains the following:
<?php
$basedir = dirname (file);
.
If b.php is a.php or include in other directories Quoted words. The contents of the
variable $basedir or the path of the folder where the b.php resides.
instead of becoming the directory where the a.php file resides.

2) dirname (file) typically returns a directory structure of the current directory of the file to the system root. The
does not return the current file name.
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 method hints,
If you can repeat the directory up one level at a time:
For example: $d = DirName (FILE),
is actually a directory to dirname () to do parameters. Because DirName () returns the last directory without \ \ or/
, you can assume that dirname () treats the lowest-level directory as a file name when it is reused. Returns the parent directory of the
current directory as usual. This way, you get the top level of the directory.

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.