PDA

View Full Version : embarassingly simple php question




brianellisrules
Mar 12, 2004, 02:57 PM
OK, this is bad. Really bad. I've been searching online and poking around the internet and haven't found what I need. I have a feeling I'm going to feel like a fool when I see the answer.....

OK, I want to get the file path where the current file is located...

$path = $_SERVER['SCRIPT_FILENAME'];
This will kick out the path PLUS the filename. How do I get rid of the filename?



sonofslim
Mar 12, 2004, 03:12 PM
try $_SERVER["DOCUMENT_ROOT"];

or for a relative path: dirname($PHP_SELF);

brianellisrules
Mar 12, 2004, 03:49 PM
try $_SERVER["DOCUMENT_ROOT"];

or for a relative path: dirname($PHP_SELF);
I was playing around with $_SERVER["DOCUMENT_ROOT"] before, but that was only giving me up to the root directory... I wasn't aware of dirname($PHP_SELF) before, so that's what I was missing. I ended up using a combination of both:

$path=$_SERVER["DOCUMENT_ROOT"].dirname($PHP_SELF);


Thanks a bunch. I'm just trying to make my latest script a bit more robust.