If my URL is http://www.server.com/myapp/stuff/to/see and my directory structure on disk is htdocs/myapp/*, how can I extract the /myapp
I incurred a similar issue. Basically, in PHP if a file 'A.php' uses relative path to refer a resource, then the current path location used as a prefix to the relative path is of the top parent php under which 'A.php' is included.
This won't be a problem if A.php itself is top parent or when A.php sits at the same folder as is its top parent. But it will break the import otherwise.
The best solution I found was to make the reference explicitly absolute by using DIR (which gives current location of the file) and then going to the referred by from this location for e.g. DIR."/../help.php" to refer to a file help.php sitting 1 level above A.php.