An alternative way to another answer would be simply in each file you set the relative path.
Assuming the folder structure is:
+-- ./
+-- conexao
+-- conexao.php
+-- pasta1
+-- exemplo1.php
+-- pasta2
+-- exemplo2.php
+-- pasta3
+-- exemplo3.php
In the archive pasta1/exemplo1.php
:
<?php
require '../conexao/conexao.php';
In the archive pasta1/pasta2/exemplo2.php
:
<?php
require '../../conexao/conexao.php';
In the archive pasta1/pasta2/pasta3/exemplo3.php
:
<?php
require '../../../conexao/conexao.php';
You can also create an index.php file along with . htaccess and it would access any file.
The file should look something like . htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*) index.php/$1 [QSA,L]
</IfModule>
And the index.php
should look like this:
<?php
require 'conexao/conexao.php';
$pathInfo = isset($_SERVER['PATH_INFO']) $_SERVER['PATH_INFO'] : '';
$pathInfo = ltrim($pathInfo, '/');
if (empty($pathInfo)) {
echo 'Index normal';
} else if (is_file($pathInfo)) {
require $pathInfo;
} else {
header('X-PHP-Response-Code: 404', true, 404);
echo 'Página não encontrada';
}
seek to use absolute paths. One way to do this is to use
$_SERVER['DOCUMENT_ROOT']
– Marcos Regis
Thanks for the prompt reply. Have some reference, so I can read?
– Hebert Richard
Try to define some directories - http://answall.com/questions/97525/get-direct%C3%B3rio-general-do-project-php/97545#97545
– Edilson