How to get absolute path on a web server using PHP ?

We can find absolute path in different ways on a web server using php, i am showing some of that practices here

01 <?php
02 echo realpath(dirname(__FILE__));
03 // realpath() , This function removes all symbolic path and returns the absolute path name , this function return >false an failer
04 //dirname() , Returns the parent directory path
05 // __FILE__ ,The full path and file name of the file
06 ?>
07 <?php
08 echo getcwd();
09 //getcwd(), function get the current working directory , returns true on success return >false on failure
10 ?>
11 <?php
12 print_r($_SERVER['DOCUMENT_ROOT']);
13 //$_SERVER is an array with headers,path,script location information.
14 //$_SERVER['DOCUMENT_ROOT'] , returns the current  executing script directory
15 ?>
16 <?php
17 // absolute path with file name
18 echo $_SERVER['SCRIPT_FILENAME'];
19 ?>

The description of the functions used in this tutorial are as follows
realpath() , This function removes all symbolic path and returns the absolute path name , this function return false an failure
dirname() , Returns the parent directory path
getcwd(), function get the current working directory , returns true on success return flase on failure
$_SERVER is an array with headers,path,script location information.

Advertisements

2 thoughts on “How to get absolute path on a web server using PHP ?

  1. Pingback: PHP « amithmehta
  2. Pingback: PHP « amithmehta

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s