Skip to content

Instantly share code, notes, and snippets.

@projectivemotion
Last active May 25, 2018 18:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save projectivemotion/c3ca6c7c2ec2022ec547a415618dfb1c to your computer and use it in GitHub Desktop.
Save projectivemotion/c3ca6c7c2ec2022ec547a415618dfb1c to your computer and use it in GitHub Desktop.
Get unresolved path of symlinked php file. Does the opposite of realpath().
<?php
/**
* Returns the Symlink (Non-Realpath) of the current script.
* I am not so sure how well this function works from inside include's.
* Use case:
*
* [amado@gravedigger phpcode]$ php -f subdir/mysymlink/subdir/mysymlink/subdir/mysymlink/app.php
* PWD: /tmp/phpcode
* SCRIPT_FILENAME: subdir/mysymlink/subdir/mysymlink/subdir/mysymlink/app.php
* ___FILE__ : /tmp/phpcode/app.php
* getSymlink(): /tmp/phpcode/subdir/mysymlink/subdir/mysymlink/subdir/mysymlink
*
* @author: Amado Martinez
* @website: http://amadomartinez.mx/
*/
function getSymlink(){
$spath = $_SERVER['SCRIPT_FILENAME'];
if($spath[0] != '/')
return dirname(getenv('PWD') . '/' . $spath);
return $spath;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment