This is the code I ended up adapting and writing...
=====
<?php
function whatdir($directory)
{
// make a array of the string splitted by a slash
$arr = explode("/",$directory);
// take the filename from the end of the array
$lastelement = array_pop($arr);
// loop through the array and
for ($n=0; $n != sizeof($arr); $n++)
{
if ($n != 0) // don't start the string with a slash
$strnew .= "/"; // place a slash
$strnew .= $arr[$n]; // append the value
}
return $strnew; //sends info back to calling program
}
?>
Then I could run the following script:
=====
<?php
$fpath = $_SERVER['SCRIPT_URL'];
echo whatdir($fpath); // returns 1/2/3/...
?>
and it will display the working web directory. If I used SCRIPT_URI instead of SCRIPT_URL I could get a full directory listing, but for my needs SCRIPT_URL works just fine.