include failed to open stream

Asked

Viewed 1,855 times

1

Ladies and gentlemen, please help me.

I have a.php client file, which has a client table to fill.

The data that will fill this table is in the Client.php class.

I am therefore using a include 'Client.php' at the beginning of the file, as follows:

<?php 

include 'Classes/Template/Client.php'; ?>

<title>Clientes | </title>
mais algum código html...

The.php Client file also has a include, as follows:

<?php 

include 'Persistencia/ClienteCRUD.php';

class Cliente {

    private $cpf;
    private $nome;
    private $crud;

    public function __construct() {
        $this->crud = new ClienteCrud();
    }

    public function getCpf() {
        return $this->cpf;
    }

    public function getNome() {
        return $this->nome;
    }

    public function setCpf($cpf) {
        $this->cpf = $cpf;
    }

    public function setNome($nome) {
        $this->nome = $nome;
    }

    public function inserir() {
        return $this->crud->create($this);
    }

    public function alterar() {
        $this->crud->update($this);
    }

    public function excluir() {
        $this->crud->delete($this);
    }

    public function listar() {
        $result = $this->crud->read();
        return $result;
    }

}

?>

Well, the following mistake is making:

Warning: include(Persistencia/Clientecrud.php): failed to open stream: No such file or directory in C: xampp htdocs inove gentelella-master Production Classes Modelo Cliente.php on line 3

Well, honestly, I don’t know what’s going on. The 'clients.php' file is located in the Production directory. The file 'Client.php' is in Production/Classes/Template/ The file 'Clientecrud.php' is in Production/Classes/Persistence.

Guys, I’ve done a lot of research, but I honestly don’t know what’s wrong. Please, if you can help me, I’ll be very grateful, because I’m stuck on this project just because of this.

NOTE: I have to use PHP without any help from any framework.

Thank you

  • Go back to a directory like this include '../Persistencia/ClienteCRUD.php';

  • Same error: Warning: include(../Persistencia/Clientecrud.php): failed to open stream: No such file or directory in C: xampp htdocs inove gentelella-master Production Classes Template Client.php on line 3 This is what I’m missing... And the file is there. It doesn’t seem to recognize '.. /' as 'going back to a directory'

  • @Gabrielaugusto as this the directory structure of his project?

  • where this class is located Client ?, do the following get the two paths and compare them to see if everything is as desired.

  • 1

    Try to do: require __DIR__ . '/../Persistencia/ClienteCRUD.php';

  • @cat *gentelella-master **Production ***Classes ****Bank *****Connection.php ****Model *****Client.php ****Persistencia *****Sign up client.php &#### ***clients. Sorry, I’m not used to using stackoverflow, so I don’t know which is the right way to represent a directory here. Anyway, I can send the github link where the project is, if allowed. Thank you

  • 1

    back 2 directories... ../../Persistencia/ClienteCRUD.php

  • @cat Pus require DIR . '/../Persistence/Clientecrud.php' in this class and another class that Clientecrud.php also requires, and it worked well. I’m using the absolute path, doing this, right? Thank you so much for your help. I believe I have to do this for all requires of all other classes, right? Guys, thanks. In case I have another problem of this type I will post!

  • @Gabrielaugusto I use this magic constant in my projects, I suggest you do for the other paths.

Show 4 more comments

1 answer

3


You can use the magic constant:

require __DIR__ . '/../Persistencia/ClienteCRUD.php';

It contains the file directory, and the directory name does not have a bar / at the end, unless it is the root directory /, then remember to put the bar if it is not at the root.

Browser other questions tagged

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