Get full path name.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Get full path name.

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Get full path name.

Post 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.
Post Reply