1# C:\Users\Redacted\Desktop\main.php
2include __DIR__ . DIRECTORY_SEPARATOR . 'include.php';
3echoScriptPath();
4
5# C:\Users\Redacted\Desktop\include.php
6function echoScriptPath() {
7 list($scriptPath) = get_included_files();
8 echo 'The script being executed is ' . $scriptPath;
9}
1// File in htdocs MAMP
2echo getcwd(); //Users/Example/Applications/MAMP/htdocs
1SplFileInfo.
2
3$path = new SplFileInfo(__FILE__);
4echo 'The real path is '.$path->getRealPath();