mapping relative path to absoulte path

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
DoppyNL

Wed Oct 16, 2002 11:16 am

I don't know how to convert a relative path wich got ".." in it to an absolute path, but you could write some code that can do it or do it by hand.
The absolute path to the current script can be found in $_SERVER['DOCUMENT_ROOT']

I only can't seem to find out why you want to convert it... They both work...

Greetz Daan

Jay

Wed Oct 16, 2002 1:16 pm

There is a way, but it's not 100% bullet proof! You can take the full document root path of the file you're in, and traverse up and down the levels based on the relative path to find it's absolute path.

What you'd need to do is explode it using / so it splits up all the directories. In the relative path, see how many directories it travels up, and delete that many dirs (remove the file first) off the end of the array, then append the rest of the URL.

This is actually what I do with my sites. The first bit works out where the file is in relation to the site, and sets up session variables. Each and every other script can call any other one by working out where they are. I can change my server OS, or path pattern and it'll still work!

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests