Find File Path At Server Using PHP

by Hiroshi on August 7, 2008

in File, URL, Useful Scripts

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'])
?>

Display
/CurrentpageURL.php

<?php
echo $_SERVER['REQUEST_URI']
?>

Display
/CurrentpageURL.php

<?php
$url = sprintf("%s%s%s","https://",$HTTP_HOST,$REQUEST_URI);
echo "$url";
?>

Display
https://localhost/CurrentpageURL.php

<?php
$sPage = explode("/", $_SERVER['PHP_SELF']);
$rs= $sPage[count($sPage)-1];
echo "$rs";
?>

Display
CurrentpageURL.php

Download Script

Related Posts

Previous post:

Next post: