Page 1 of 1

Get full path name.

Posted: Fri Feb 06, 2009 1:02 pm
by Skoalbasher
Ok, this is getting annoying.

I need to get the full path of whatever folder my php file is in.

right now it's in http://www.schoolofdan.com/storage/

This is what I have so far, and it outputs the right info, but there has to be a better way

Code: Select all

 
$test = explode("/", $_SERVER['PHP_SELF']);
$test1 = $test[1];
 
$tester = "http://".$_SERVER['SERVER_NAME']."/".$test1."/";
 
foreach (glob("*.jpg") as $filename) {
    echo "<a href='$filename'><img src='$filename' border='0'><a><br>";
    echo "BBCODE - <input type=\"text\" name=\"sig\" value=\"[url=http://www.schoolofdan.com][img]".$tester.$filename."[/img][/url]\" size=\"50\"><br><br>";
}
 
Pretty much it's a signature and it prints the BB Code for you to cut and paste. Check here http://www.schoolofdan.com/storage

Again, I'm getting the correct output, but there has to be something better. If I don't use explode I still get the index.php at the end. I don't want that.

Re: Get full path name.

Posted: Fri Feb 06, 2009 4:49 pm
by requinix
The only room for improvement I see is how you get $test1.

A combination of dirname and $_SERVER["SCRIPT_NAME"] (not PHP_SELF) should suit you better.