note 57420 deleted from function.realpath by nlopess
| From: | nlopess@php.net | Date: | Tue, 25 Jul 2006 11:31:23 +0000 |
| Subject: | note 57420 deleted from function.realpath by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-115136@lists.php.net to get a copy of this message | ||
Note Submitter: nospam at savvior dot com
----
Hello, I was having problems getting realpath to work on a windows shared hosting machine and used
this function to resolve it... hope this helps someone
Code:
<?
function realpath2($path)
{
////check if realpath is working
if (strlen(realpath($path))>0)
return realpath($path);
///if its not working use another method///
$p=getenv("PATH_TRANSLATED");
$p=str_replace("\\","/",$p);
$p=str_replace(basename(getenv("PATH_INFO")),"",$p);
$p.="/";
if ($path==".")
return $p;
//now check for back directory//
$p=$p.$path;
$dirs=split("/",$p);
foreach($dirs as $k => $v)
{
if ($v=="..")
{
$dirs[$k]="";
$dirs[$k-2]="";
}
}
$p="";
foreach($dirs as $k => $v)
{
if (strlen($v)>0)
$p.=$v."/";
}
$p=substr($p,0,strlen($p)-1);
if (is_dir($p))
return $p;
if (is_file($p))
return $p;
return false;
}
?>