note 74908 deleted from function.realpath by danbrown
| From: | danbrown@php.net | Date: | Mon, 01 Jun 2009 13:01:59 +0000 |
| Subject: | note 74908 deleted from function.realpath by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156236@lists.php.net to get a copy of this message | ||
Note Submitter: Marc Noirot
----
Yet another realpath replacement:
function myRealPath($path) {
// Check if path begins with "/". => use === with strpos
if (strpos($path,"/") === 0) {
$path = $_SERVER['DOCUMENT_ROOT'].$path;
}
else {
// Strip slashes and convert to arrays.
$currentDir = preg_split("/\//",dirname($_SERVER['PATH_TRANSLATED']));
$newDir = preg_split('/\//',$path);
// Drop one directory from the array for each ".."; add one otherwise.
foreach ($newDir as $dir) {
if ($dir == "..")
array_pop($currentDir);
elseif ($dir != ".") //test for "." which represents current dir (do
nothing in that case)
array_push($currentDir,$dir);
}
// Return the slashes.
$path = implode($currentDir,"/");
}
return $path;
}