On 13/08/11 12:31, Chris G wrote:
On Sat, Aug 13, 2011 at 11:56:07AM +0100, Chris G wrote:
The subject says it all really.
For example I have a directory /var/www/wiki/lib/plugins/indexmenu which is a symbolic link to /home/chris/src/dokuwiki-plugins/indexmenu. I want a way (in PHP in particular) to be able to navigate up to /var/www/wiki but everything I try program-wise takes me back to the /home/chris tree.
I'm sure on the old SunOs/Solaris systems I used if you navigated up on the command line it didn't go backwards up symbolic links, but on this xubuntu 10.04 system if I do, for example, 'ls ../..' when I'm in /var/www/wiki/lib/plugins/indexmenu I see the contents of /home/chris/src which somehow feels wrong to me.
The real issue is in PHP though as there are many places in dokuwiki which use ../../.. to access things and there doesn't seem to be an easy way to do this when there are symbolic links involved. One can use regular expressions to prune /var/www/wiki/lib/plugins/indexmenu down to /var/www/wiki/ but this seems a bit of a sledgehammer to crack a nut.
More to the point after a little further testing the *real* problem is that __FILE__ resolves to the 'real' name of the file, with symbolic links resolved.
So __FILE__ in the file /var/www/wiki/lib/plugins/indexmenu/fred.php is '/home/chris/src/dokuwiki-plugins/indexmenu/fred.php' so however I manipulate it I can't get to /var/www/wiki. What I need is a way to find the home directory of a file in PHP and I can't really see any practical way of doing it.
So, given a file /var/www/wiki/lib/plugins/indexmenu/fred.php where indexmenu is a symbolic link, how can fred.php work out that it is in directory /var/www/wiki/lib/plugins/indexmenu?
I dunno if this will help but pwd -P will give the physical directory. Maybe calling that from php with the shell_exec function.