Having the folder structure down:
Considering I’m in the file conteúdo.html
and want to include the archive horas.html
, as the two are on the same level folders so I should use:
include "./horas.html";
To include the archive dicas.html
that’s in the folder recursos
I shall use:
include "./recursos/dicas.html";
Since the folder recursos
is on the same level as conteúdo.html
Now to include the file catálogo.html
that’s in the folder produtos
I shall use:
include "../produtos/catálogo.html";
So I will go up a level between the folders and from there insert the path of the desired file.
But knowing that the folder produtos
is a folder that is in the root folder I can use:
include "/produtos/catálogo.html";
So
In src='./somePath';
the ./
means you are referring to the current folder
In src='../somePath';
the ../
means that you are referencing a folder prior to the current one. You can use several to search in folders at different levels.
Example:
src='../../../otherPath';
here I am looking for the folder otherPath
in a folder that is 3 levels above the folder where the current script is running.
In src='/somePath';
0 /
means that you are referring to the system root folder
A tip off friend, to avoid problems with inclusions of different locations, it is best to put the whole way in the includes. As for example
define('FULL_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . '/'); include FULL_PATH . 'pasta/meu-arquivo.php';
. Use thisdefine
only in a file in the root folder of your project, to access is "constant", include it in a global file and include this file in other :)– Guilherme Nascimento