Categories: Tutorials

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

// 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:

getPageURL();    // returns "http://localhost/live/uploadProductImage.php"
getCurrDir();    // returns "http://localhost/live/"
Larry Battle

I love to program, and discover new tech. Check out my stackoverflow and github accounts.

Share
Published by
Larry Battle
Tags: php

Recent Posts

What really is Data Science? Told by a Data Scientist

What REALLY is Data Science? Told by a Data Scientist - By Joma Tech

7 years ago

Video: How Water Towers Work

How Water Towers Work - Practical Engineering

7 years ago

Dev Tip: Simple tips to improve code reviews

Writing perfect code is a challenging process. That's where code reviews come in to help…

7 years ago

Video: How AI will change the 3d industry

"The Next Leap: How A.I. will change the 3D industry - Andrew Price - Blender"

7 years ago

Best Software Presentation for 2018

"Captain Disillusion: World's Greatest Blenderer - Live at the Blender Conference 2018 - CaptainDisillusion"

7 years ago

Dev Video: A Few Linux Shell Tips

My 5 Favorite Linux Shell Tricks for SPEEEEEED (and efficiency) - By tutoriaLinux > What's…

7 years ago