Handling Paths

Does anyone know a good read up on how to handle paths?

Im playing around with $_SERVER, PHP_SELF, basename, realpath, etc, and Im in a mess using …/…/ etc.

Id like to figure out how to get the lowest level where my application is, like a subfolder on a domain.

ie: http://workspace/fk2/index.php

if Im in
http://workspace/fk2/application/controller/file.php
how can I set /fk2/ as the root?
I dont want it to be workspace, know what im saying?

If I manually require a constant like:
define(‘url’, ‘http://workspace/fk2/’);

I can’t do that for includes because i have furl set off and dont wanna turn it on.

The easiest way is to always go though index.php at the lowest level.

so should I define a constant in index.php for example (or anything thats the lowest level)

define(‘root’, dir(FILE));

and if Im up in /app/blah/ehh
I can say root . ‘filename.php’
and it’ll call from that area?