Solution to the PHP dirname (_ FILE _) path in linux

Source: Internet
Author: User

Recently, when developing templates for wordpress, we found that path errors may occur when calling other php code snippets in the form of include ("file name. Previously, the server environment was always iis, and no similar bugs were found. However, after being replaced with a linux server, a path call error occurred. I searched the internet and found that the dirname (_ FILE _) can be used to solve the path error when the linux Server contains files.

In fact, the main problem is the root directory of the site under the linxu server. When the linux Server contains a file, the path is/home/web /. If you directly use the include ("/file name") format, the actually contained file path is/home/web/file name.

The complete method is include dirname (_ FILE _). '/page. php'

The FILE referenced by this code must be in the same directory as the FILE where the code is located. If you need to call the previous directory, you can use dirname (_ FILE __)) to call the files in the previous directory.

If you encounter inclusion problems after changing the server, check whether the website has a Reference Path error. We recommend that you use the dirname (_ FILE _) method to reference a FILE when writing a php FILE to solve the reference problem in most cases.

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.