mapping relative path to absoulte path

A

Anonymous

Guest
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
 
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!
 
Back
Top