Identifying file path with pathinfo

Asked

Viewed 67 times

0

Well I set up 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 me the path of the function file, and I need it to return me the path of the index.php file..

Someone knows what I’m doing wrong?

1 answer

2

You can use the global $_SERVER to display the running file path.

$_SERVER['SCRIPT_FILENAME']

In the case of your role, you would be:

function Local() {
    return $_SERVER['SCRIPT_FILENAME'];
}
  • However, if I call the function in one file, and call this file inside another with a 'include', the path that returns me is not from the file where the function is being called. I need to identify the file where the function is called, regardless of whether it is placed in a include within another file. You understood my explanation?

Browser other questions tagged

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