Find Path Of File At Server Using PHP

by Hiroshi on August 7, 2008

in URL, Useful Scripts

Previously I have mentioned some ways to find out file name at server also. This script tells the exact path of file at server. I have tested it at local host and my sweet wamp server is installed in my D drive of PC.

<?php
print $_SERVER['SCRIPT_FILENAME']
//tells the path of the file
?>

Display
d:/wamp/www/test/file path at server.php

Download Script

You can also try these scripts. In my case page location was following.
https://localhost/srcExamples/filepath.php

Finding Root Dirctory path

<?php
echo $file=$_SERVER['DOCUMENT_ROOT'];
?>

Display
d:/wamp/www

<?php
   $string = $_SERVER['PHP_SELF'];
   $currentPage= str_replace("/","",$string);
   echo $currentPage;
?>

Display
srcExamplesfilepath.php

<?php
   $string = $_SERVER['PHP_SELF'];
   $currentPage= str_replace("/","/",$string);
   echo $currentPage;
?>

Display
/srcExamples/filepath.php

Download Script

Related Posts

Previous post:

Next post: