function getRealpath($_path) { /* * This is the starting point of the system root. * Left empty for UNIX based and Mac. * For Windows this is drive letter and semicolon. */ $__path = $_path; if (isRelative($_path)) { $__curdir = unifyPath(realpath(".") . _PL_OS_SEP); $__path = $__curdir . $__path; } $__startPoint = ""; if (checkCurrentOS("Win")) { list($__startPoint, $__path) = explode(":", $__path, 2); $__startPoint .= ":"; } # From now processing is the same for WIndows and Unix, and hopefully for others. $__realparts = array(); $__parts = explode(_PL_OS_SEP, $__path); for ($i = 0; $i < count($__parts); $i++) { if (strlen($__parts[$i]) == 0 || $__parts[$i] == ".") { continue; } if ($__parts[$i] == "..") { if (count($__realparts) > 0) { array_pop($__realparts); } } else { array_push($__realparts, $__parts[$i]); } } return $__startPoint . _PL_OS_SEP . implode(_PL_OS_SEP, $__realparts); }
function resolve_path($base, $path) { $base = str_replace('\\', '/', $base); $path = str_replace('\\', '/', $path); if (substr($base, -1) == '/') { $base = substr($base, 0, -1); } $base = explode('/', $base); $path = explode('/', $path); // del unnecessary elements $path = array_diff($path, array('', '.')); while ($dir = array_shift($path)) { if ($dir == '..') { array_pop($base); continue; } $base[] = $dir; } if (checkCurrentOS("Win")) { array_shift($base); return implode('/', $base) . '/'; } else { return implode('/', $base) . '/'; } }