Well I've done it using this function:
<?php
function public_base_directory()
{
//get public directory structure eg "/top/second/third"
$public_directory = dirname($_SERVER['PHP_SELF']);
//place each directory into array
$directory_array = explode('/', $public_directory);
return $directory_array[1];
}
?>
It seems to work OK, but will have to see if I run into any problems with it later.