Identifying path of the file with pathinfo

0

Well I put a function in the local.php file:

function Local() {

    $path_parts = pathinfo( __FILE__ );
    $arquivo = "".$path_parts['dirname']."/".$path_parts['basename'];

    return $arquivo;
}

I call the function in the index.php file like this:

include "local.php";

echo Local();

The problem is that it is returning the path of the function file, and I need it to return the path to the index.php file.

Does anyone know what I'm doing wrong?

    
asked by anonymous 03.03.2017 / 14:32

1 answer

2

You can use the global $ _SERVER to display the path of the file being executed.

$_SERVER['SCRIPT_FILENAME']

In the case of its function, it would only be:

function Local() {
    return $_SERVER['SCRIPT_FILENAME'];
}
    
03.03.2017 / 15:24