PHP dirname (__file__) path problem solving _php tutorial in Linux

Source: Internet
Author: User
Recently, when developing template functionality for WordPress, it was found that a path error occurred when invoking other PHP snippets directly in the form of include ("File name"). The server environment was always IIS, and there were no similar bugs, but a path call error occurred after switching to a Linux server. After searching the internet, we found that you can use DirName (__file__) to resolve the path error when the Linux server contains files.

In fact, the main problem comes from the site root directory under the Linxu server, and when a file is included under a Linux server, its path is/home/web/. If you use the format of the include ("/file name") directly, the file path that is actually contained is/home/web/file name.

The complete use method is include DirName (__file__). '/page.php '

The file referenced by this code needs to be in the same directory as the file where the code resides, and if you need to call the previous directory, you can use DirName (dirname (__file__)) to invoke the file from the previous level directory.

If you encounter a problem with the included class after you have replaced the server, you may want to check if the site has a reference path error. It is recommended that you use the DirName (__file__) method to refer to the file when writing PHP inclusions to resolve the reference problem in most cases.

http://www.bkjia.com/PHPjc/626580.html www.bkjia.com true http://www.bkjia.com/PHPjc/626580.html techarticle recently, when developing template functionality for WordPress, it was found that a path error occurred when invoking other PHP snippets directly in the form of include (file name). Before the server environment is always IIS, ...

  • 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.