I have other solutions to find file path at server or file name using PHP. The thing is, some php scripts might not work with some versions of PHP or in some situations. So more methods you learn for each task with PHP, the better. Here goes more solutions; Enjoy!
In this example I used CurrentpageURL.php page and tested it via wamp server at local host.
<?php echo htmlspecialchars($_SERVER['REQUEST_URI']) ?>
<?php echo $_SERVER['REQUEST_URI'] ?>
<?php $url = sprintf("%s%s%s","https://",$HTTP_HOST,$REQUEST_URI); echo "$url"; ?>
<?php $sPage = explode("/", $_SERVER['PHP_SELF']); $rs= $sPage[count($sPage)-1]; echo "$rs"; ?>