Created
November 5, 2013 14:23
-
-
Save dave1010/7319741 to your computer and use it in GitHub Desktop.
De-resolve symlinks from PHP's __FILE__
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function deResolveSymlinks($file) | |
{ | |
$included = get_included_files(); | |
if(array_search($file, $included) !== false) { | |
return $file; | |
} | |
foreach($included as $include){ | |
if(is_link($include) && readlink($include) === $file) { | |
// an included file resolves to __FILE__ | |
return $include; | |
} | |
} | |
return false; | |
} | |
echo deResolveSymlinks(__FILE__) . PHP_EOL; | |
5 years later... is there a better solution ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work when the directory is the symlink rather than the php file directly.
In this case, it still resolves the symlink.