Home > Backend Development > PHP Tutorial > Solution to the problem that the file introduced by the PHP require_once() function cannot be found

Solution to the problem that the file introduced by the PHP require_once() function cannot be found

黄舟
Release: 2023-03-11 12:16:01
Original
4293 people have browsed it


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');
Copy after login
Copy after login

It looks really good, but I am The code user.class.php

require_once("class/user.class.php");
Copy after login

introduced in index.php

looks good, but the following error is reported when running:
Solution to the problem that the file introduced by the PHP require_once() function cannot be found

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');
Copy after login
Copy after login

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!

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