problem with PHP file path

Asked

Viewed 177 times

0

Good evening, I’m having problems doing include of a file I use to register data in my database, I’m getting the error: Warning: require(./cadastro/usuario/usuario.php): failed to open stream: No such file or directory in C: xampp htdocs Projeto_biblioteca validadores validador_usuario validar_usuario.php on line 5. I am in the file validators/validar_usuario/validar_usuario.php and I am trying to include in this file the path of the user.php file that is like this: registration/user/user.php as shown below, this file is my class of registering users in the database and the file validar_usuario.php is where I am sending the data of my form and making include of my registration class, I would like a help to specify the path correctly since I tried several ways and have not solved the problem yet

inserir a descrição da imagem aqui

2 answers

1


Based on the project structure presented in the question image, you will have to go back 2 levels in your require. Note that if you go back only 1 level, it really won’t exist in your project "Project_library/validators/register/user/user.php".

require('../../cadastro/Usuario/usuario.php');

Anyway you could refer to the root directory of the application (take a look at $_SERVER - DOCUMENT_ROOT) to avoid problems in migrating your application to other directories and systems.

I hope I’ve helped.

  • Hello friend, thanks for the help helped here, now I’m studying some autoload.php Composer to load my classes, will be easier?

  • Surely Composer auto_load will help you even more, you can make it easier with namespaces. @Wilder, the best way to thank for an answer is to mark it as accepted by clicking on the visa sign ( ). But do this only if any answer has answered your original question. When you reach 15 reputation points you can also vote in favour of an answer or question. See: Someone answered me and Why vote?.

0

To access the previous directory, in Windows do "../" and not "./". For example: include('../Cadastro/Usuario/usuario.php');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.