note 36544 deleted from function.realpath by aidan
| From: | aidan@php.net | Date: | Sun, 29 Aug 2004 21:50:24 +0000 |
| Subject: | note 36544 deleted from function.realpath by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75605@lists.php.net to get a copy of this message | ||
Note Submitter: Marc Noirot
----
This is a correction to John's realpath replacement function :
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;
}