1
Well I have a function where I need to load a include file into the function. Kind like this:
function Query($conexao, $query) {
// Includes
include "../Dados.php";
}
the problem is that in some files in which I call the function it does not locate the data file. This is because some files are inside some folders. Is there any way to make include fetch the data file at the root of the site? Or regardless of where I call the function it goes at the root and searches the file.
If you replicate this function on several pages you will need to point the way, if your function is in a single script and you simply call it you can use the predefined constants as DIR which will point to the directory from its script containing the function. http://php.net/manual/en/language.constants.predefined.php
– Lauro Moraes
The 'DIR' has been replaced by 'FILE' in PHP 5.6 if I am not mistaken. So the function is in a single scrip, so I avoid duplicating code. I call the function file on the page I want with a 'include', and then call the function.
– Hugo Borges
Note that I did not cite the function
dir()
of bad directories yes to default count__DIR__
functional in php 7.1.*– Lauro Moraes
Right. Ta mais
__DIR__
will return me the path where the 'incluide' is and I always need to return to the root folder– Hugo Borges
Why not use a constant with the absolute path of the file?
– ShutUpMagda