Home > Backend Development > PHP Tutorial > Solving the problem of PHP dirname(__FILE__) path in linux_PHP tutorial

Solving the problem of PHP dirname(__FILE__) path in linux_PHP tutorial

WBOY
Release: 2016-07-13 17:17:30
Original
797 people have browsed it

Recently, when developing template functions for WordPress, I discovered that a path error would occur when directly using include ("file name") to call other PHP code snippets. The server environment has always been iis before, and similar bugs have never occurred. However, after switching to a linux server, a path calling error occurred. After searching on the Internet, I found that dirname(__FILE__) can be used when calling to solve the path error when including files under the Linux server.

In fact, the main problem comes from the site root directory problem under the linxu server. When a file is included under the linux server, its path is /home/web/. If you use the include("/filename") format directly, the actual included file path is /home/web/filename.

The complete usage 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 is located. If you need to call the upper directory, you can use dirname(dirname(__FILE__)) to call the file in the upper directory.

If you encounter inclusion problems after changing the server of your website, you may wish to check whether there are any reference path errors on the website. It is recommended to use the dirname(__FILE__) method to reference files when writing PHP includes to solve reference problems in most cases.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/626580.htmlTechArticleRecently, when developing the template function for wordpress, I discovered that other PHP code snippets are directly called in the form of include (file name). A path error will occur. The server environment has always been iis before,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template