This one will put both the "www" and "file" path into an easy to transport array. 
 
<?php 
// build the www path: 
$me = $_SERVER['PHP_SELF']; 
$Apathweb = explode("/", $me); 
$myFileName = array_pop($Apathweb); 
$pathweb = implode("/", $Apathweb); 
$myURL = "http://".$_SERVER['HTTP_HOST'].$pathweb."/".$myFileName; 
$PAGE_BASE['www'] = $myURL;  
// build the file path: 
strstr( PHP_OS, "WIN") ? $strPathSeparator = "\\" : $strPathSeparator = "/"; 
$pathfile = getcwd (); 
$PAGE_BASE['physical'] = $pathfile.$strPathSeparator.$myFileName;  
// this is so you can verify the results: 
$www = $PAGE_BASE['www']; 
$physical = $PAGE_BASE['physical'];  
echo "$physical<p>"; 
echo "$www<p>"; 
?>  
The following will return something like:  
Windows: 
F:\dev\Inetpub\wwwroot\somedirectory\index.php  
http://devserver/somedirectory/index.php  
Unix: 
/home/somepathto/gieson.com/webroot/index.php  
http://www.gieson.com/index.php