Today I used php to write a simple Android login server code. I encountered a particularly depressing thing, using require_once() An error message appears for the file introduced into the php file and the file cannot be found.
require_once() in php is mainly used to introduce one php file into another php file. Let me first talk about the problems I encountered. My directory structure is like this:
This is what I wrote in user.class.php:
require_once("../config/mysqlConfig.php");require_once('../util/HandleMysql.class.php');
It looks really good, but I am The code user.class.php
require_once("class/user.class.php");
looks good, but the following error is reported when running:
I thought about it and finally found the problem:
require_once()Function actually puts the code of the file you included into the location where you referenced, that is to say , after the above two references, in fact, the index.php file now looks like this
require_once("../config/mysqlConfig.php");require_once('../util/HandleMysql.class.php');
Then index.php follows this path to find these two The file, of course, cannot be found.
It seems that relative paths should be used with caution in actual development.
The above is the detailed content of Solution to the problem that the file introduced by the PHP require_once() function cannot be found. For more information, please follow other related articles on the PHP Chinese website!