_php tutorial on solving php relative directory problems

Source: Internet
Author: User
When you include a file with include or Requice, the file path is preceded by DirName (__file__). For example: Existing a.php, b.php, c.php, D.PHP4 files, their relationship is:

B.php (same level as root directory)
Root directory/a.php
Root directory/c.php
Root directory/dir/d.php

Now a.php to include b.php, c.php. The wording is as follows:

Include_once (DirName (__file__). " /.. /b.php ");
Include_once (DirName (__file__). " /c.php ");
?>
If you want to include d.php in c.php. The wording is as follows:
Include_once (DirName (__file__). " /dir/d.php ");
?>
This approach is currently the most effective way to solve the problem of path dislocation.

http://www.bkjia.com/PHPjc/371453.html www.bkjia.com true http://www.bkjia.com/PHPjc/371453.html techarticle when you include a file with include or Requice, the file path is preceded by DirName (__file__). For example: Existing a.php, b.php, c.php, D.PHP4 files, their relationship is: b.php (same as root 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.