Include in previous folder

Asked

Viewed 3,112 times

1

I have the following include:

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

on the pages that are the same folder as the include header works, but when there is a folder above it doesn’t work.

pastas

The include page is inside the pages/1998

the following errors are issued:

Warning: include_once(../acoes/conexao.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(../acoes/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 '.. /acoes/pagina_verify.php' (include_path='C: Xampp php PEAR') in C: xampp htdocs PMI-WEB-CONTAB-ALPHA pages header.php on line 11

2 answers

3

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

It is also possible to navigate between pages like: ../js/arquivo.js

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

  • worked in parts, but the page did not take CSS and Bootstrap, issued the following errors: Warning: include(../.header.php): failed to open stream: No such file or directory in C: xampp htdocs PMI-WEB-CONTAB-ALPHA pages 1998 reports_financeiros_98.php on line 2 Warning: include(): Failed Opening '.. /.. /header.php' for inclusion (include_path='C: Xampp php PEAR') in C: xampp htdocs PMI-WEB-CONTAB-ALPHA pages 1998 reportarios_financeiros_98.php on line 2 Notice: Undefined variable: _SESSION in C: xampp htdocs PMI-WEB-CONTAB-ALPHA pages 1998 reports_financeiros_98.php on line 4

  • That first Warning that you presented is that now the header page is not being found. In which folder is the file that calls your include?

  • he stays in the 1998 folder

  • So the include scam is really ../header.php. This include is not wrong. The problem is elsewhere

  • have any idea what it could be?

  • pq pages that are in the same folder as the header are working perfectly

  • Got it. The problem is include inside header.php, because when it is called from inside a file inside the 1998 folder, the call ../acoes/conexao.php in header.php line 5 is incorrect from the inside view of the 1998 folder, you would need a ../the most

  • 1

    To do this, use friend @Valdeir Psr’s suggestion to create a constant on your system that allows you to always know the path of include from it

Show 3 more comments

1

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

So you should add the includes as if you were on index.php.

File structure:

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

index php.

<?php

include "sd/teste2.php";

php test.

Olá

sd/teste2.php

<?php

include "teste.php";

Tip 1: To avoid this type of error, create a constant with the index.php and use when including a file. define("PATH", __DIR__); include PATH."/acoes/file.php"

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

/paginas/header.php = On linux means you’re taking the file on <raiz-do-servidor>/paginas/header.php

/paginas/header.php = On Windows means you’re picking up the file on C:\paginas/header.php

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

  • my header is a folder above (relative to index.php), inside pages, with: include('/pages/header.php'); it should be possible to include the header, but it does not happen...

  • If you are using the index.php which is in the same folder as the file package.json, then your include should be include('paginas/header.php');. I edited my reply. Add a hint.

  • so I’m in windows here and it’s the way you put it there, but the error persists

  • Warning: include(pages/header.php): failed to open stream: No such file or directory in C: xampp htdocs PMI-WEB-CONTAB-ALPHA pages 1998 reports_financeiros_98.php on line 2 Warning: include(): Failed Opening 'pages/header.php' for inclusion (include_path='C: Xampp php PEAR') in C: xampp htdocs PMI-WEB-CONTAB-ALPHA pages 1998 reports_financeiros_98.php on line 2 Notice: Undefined variable: _SESSION in C: xampp htdocs PMI-WEB-CONTAB-ALPHA pages 1998 reports_financeiros_98.php on line 4

  • Put the following in the index.php file (at the top). die( __DIR__ ); and check the page. Then just follow this folder as the basis.

  • at the top is in the head?

  • If possible in the first line of index.php. <?php die( __DIR__ ); ?>

  • C: xampp htdocs PMI-WEB-CONTAB-ALPHA -- that’s what appeared, to get to the header you should only enter "pages"... I don’t know what’s wrong

Show 4 more comments

Browser other questions tagged

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