Include in previous folder

1

I have the following include:

include('../header.php');

In the pages that are the same folder as the include header works, however when a folder above does not work,

  

The page that has the include is inside pages / 1998

The following errors are issued:

  

Warning: include_once (../ actions / connection.php): failed to open stream: No   such file or directory in   C: \ xampp \ htdocs \ PMI-WEB-CONTAB-ALPHA \ pages \ header.php on line 5

     

Warning: include_once (): Failed opening '../acoes/conexao.php' for   inclusion (include_path = 'C: \ Xampp \ php \ PEAR') in   C: \ xampp \ htdocs \ PMI-WEB-CONTAB-ALPHA \ pages \ header.php on line 5

     

Warning: include_once (../ actions / modal.php): failed to open stream: No   such file or directory in   C: \ xampp \ htdocs \ PMI-WEB-CONTAB-ALPHA \ pages \ header.php on line 6

     

Warning: include_once (): Failed opening '../acoes/modal.php' for   inclusion (include_path = 'C: \ Xampp \ php \ PEAR') in   C: \ xampp \ htdocs \ PMI-WEB-CONTAB-ALPHA \ pages \ header.php on line 6

     

Warning: require (../ acoes / pagina_verificar.php): failed to open   stream: No such file or directory in   C: \ xampp \ htdocs \ PMI-WEB-CONTAB-ALPHA \ pages \ header.php on line 11

     

Fatal error: require (): Failed opening required   '../accessories/pagina_verify.php' (include_path = 'C: \ Xampp \ php \ PEAR') in   C: \ xampp \ htdocs \ PMI-WEB-CONTAB-ALPHA \ pages \ header.php on line 11

    
asked by anonymous 11.01.2018 / 19:02

2 answers

3

The command to upload a folder is ../ so if you want to upload another folder use ../../header.php and so on.

You can also navigate between pages like: ../js/arquivo.js

Remember that you have to make this path run from where the file that calls the include is, if the file is in the 1998 folder the correct one is ../header.php . But if the file is in actions, you should put ../paginas/header.php

    
11.01.2018 / 19:06
2

In%% of the files path is defined based on the main file, PHP .

So you should add includes as if you were in index.php .

File structure:

Desktop
│   index.php
│   teste.php
│
└───sd
        teste2.php

index.php

<?php

include "sd/teste2.php";

test.php

Olá

sd / teste2.php

<?php

include "teste.php";

Tip 1: To avoid this type of error, create a constant with the path of index.php and use it when adding a file. index.php

Tip 2: Avoid the bar at the beginning of the path, which means you are picking up from the root directory of the server.

define("PATH", __DIR__); include PATH."/acoes/file.php" = In linux it means you are getting the file in /paginas/header.php

<raiz-do-servidor>/paginas/header.php = In Windows it means that you are getting the file in /paginas/header.php

Tip 3: Always use absolute paths. Ex: /var/www/html/project/page/header.php . So the ideal is to follow tip 1 .

    
11.01.2018 / 19:11