Code of the Day: PHP, get the current directory of a page.

1
2
3
4
5
6
7
8
// Returns the current page.
function getPageURL(){
	return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
}
// getCurrDir() returns the current directory.
function getCurrDir(){
	return dirname( getPageURL() );
}

Example:

1
2
getPageURL();    // returns "http://localhost/live/uploadProductImage.php"
getCurrDir();    // returns "http://localhost/live/"
(Page view Count: 28)