Time () function, summary of Use of dirname (__file__)

Source: Internet
Author: User

The time () function returns the number of seconds from 1970-1-1 0:0:0 to the current. (Integral type)

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 full path to the file it resides in, not the full path to the file that references it.

Take a look at the following example:
/home/data/demo/test/a.php

<?php
$the _full_name=__file__;
$the _dir=dirname (__file__);
echo $the _full_name; Back to/home/data/demo/test/a.php
echo $the _dir; Back to/home/data/demo/test
?>


home/data/demo/b.php
<?php include "test/a.php";
echo $the _full_name; Back to/home/data/demo/
echo $the _dir; Return/home/data/demo/test instead of/home/data/demo/
>test/a.php, not/home/data/demo/b.php.

To put it simply:
__FILE__ returns the current path + file name
DirName (__file__) returns the path portion of the current file path
DirName (DirName (__file__)); Gets the file on the top of the directory name (does not include the last "/" number)

For example, if the current file is/home/data/demo/test.php, the
__FILE__ get is the full path is/home/data/demo/test.php, and
DirName (__file__) Gets the path part that is the/home/data/demo (no "/" number behind)

Time () function, summary of Use of dirname (__file__)

Related Article

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.