note 39706 deleted from function.realpath by aidan
| From: | aidan@php.net | Date: | Sun, 29 Aug 2004 21:50:05 +0000 |
| Subject: | note 39706 deleted from function.realpath by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75604@lists.php.net to get a copy of this message | ||
Note Submitter: napalm at spiderfish dot net
----
In response to Mario Carbonell's resolvePath function I added a little code so it can also
accept windows type fullpaths (ex: c:\folder\file.txt) for both arguments:
<?
function resolvePath2 ($dest, $orig) {
if ($dest == "") return $orig;
if ($orig == "") return $dest;
if ($dest[0] == "/" || preg_match('/^(\w:)/', $dest)) return $dest;
$prefix = "";
if ($orig[0] != "/") {
if (preg_match('/^(\w:)(\/.*)/', $orig, $match)) {
$prefix = $match[1];
$orig = $match[2];
}
else
$orig = "/".$orig;
}
//Rest of the function
return $prefix.$path;
}
?>
So... now
resolvePath2("../../file.html", "z:/home/napalm/folder/tpls/file.tpl");
returns
z:/home/napalm/file.html
Napalm