note 33011 added to function.realpath
| From: | john at rack1 dot php dot net | Date: | Fri, 13 Jun 2003 18:29:15 +0000 |
| Subject: | note 33011 added to function.realpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50299@lists.php.net to get a copy of this message | ||
for some reason or another, i couldn't get realpath to work. so i made my own. it's very
simple, but it does work. it checks vs. the current directory (the one from which the script is
being run).
--John
======
function myRealPath($path) {
// Check if path begins with "/".
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);
else
array_push($currentDir,$dir);
}
// Return the slashes.
$path = implode($currentDir,"/");
}
return $path;
}
----
Manual Page -- http://www.php.net/manual/en/function.realpath.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33011
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33011&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33011&report=yes