Ejemplo n.º 1
0
function cleanPath($path, $isLinux)
{
    $slash = getSlashDir($isLinux);
    $parts = explode($slash, $path);
    foreach ($parts as $key => $val) {
        if ($val == "..") {
            $parts[$key] = "";
            $lastKey = $key - 1;
            $parts[$lastKey] = "";
        } elseif ($val == ".") {
            $parts[$key] = "";
        }
    }
    reset($parts);
    $fixedPath = $isLinux ? "/" : "";
    //Some PHP configs wont automatically create a variable on .= or will at least whine about it
    $firstPiece = true;
    foreach ($parts as $val) {
        if ($val != "") {
            $fixedPath .= ($firstPiece ? '' : $slash) . $val;
            $firstPiece = false;
        }
    }
    if ($fixedPath == "") {
        $fixedPath = $isLinux ? $slash : $driveLetter . ":" . $slash;
    }
    //Make sure there is an ending slash
    if (substr($fixedPath, -1) != $slash) {
        $fixedPath .= $slash;
    }
    return $fixedPath;
}
Ejemplo n.º 2
0
function cleanPath($path, $isLinux)
{
    $slash = getSlashDir($isLinux);
    $parts = explode($slash, $path);
    foreach ($parts as $key => $val) {
        if ($val == "..") {
            $parts[$key] = "";
            $lastKey = $key - 1;
            $parts[$lastKey] = "";
        } elseif ($val == ".") {
            $parts[$key] = "";
        }
    }
    reset($parts);
    $fixedPath = $isLinux ? "/" : "";
    $firstPiece = true;
    foreach ($parts as $val) {
        if ($val != "") {
            $fixedPath .= ($firstPiece ? '' : $slash) . $val;
            $firstPiece = false;
        }
    }
    if ($fixedPath == "") {
        $fixedPath = $isLinux ? $slash : $driveLetter . ":" . $slash;
    }
    if (substr($fixedPath, -1) != $slash) {
        $fixedPath .= $slash;
    }
    return $fixedPath;
}