We can find absolute path in different ways on a web server using PHP, I am showing some of that practices here
1 2 3 4 |
echo realpath(dirname(__FILE__)); // 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 // __FILE__ ,The full path and file name of the file |
1 2 |
echo getcwd(); //getcwd(), function get the current working directory , returns true on success return false on failure |
1 2 3 |
print_r($_SERVER['DOCUMENT_ROOT']); //$_SERVER is an array with headers,path,script location information. //$_SERVER['DOCUMENT_ROOT'] , returns the current executing script directory |
1 2 |
// absolute path with file name echo $_SERVER['SCRIPT_FILENAME']; |
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.
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.