public static function getRelativePath($frompath, $topath = "")
    {
        if(empty($topath)) {
            $topath = $frompath;
            $frompath = getcwd();
        }

        if($frompath == ".") $frompath = getcwd();
        if($topath == ".") $topath = getcwd();

        if($frompath[0] != DIRECTORY_SEPARATOR) $frompath = getcwd().DIRECTORY_SEPARATOR.$frompath;
        if($topath[0] != DIRECTORY_SEPARATOR) $topath = getcwd().DIRECTORY_SEPARATOR.$topath;

        $from    = explode(DIRECTORY_SEPARATOR, $frompath); // Folders/File
        $to      = explode(DIRECTORY_SEPARATOR, $topath); // Folders/File
        $relpath = '';

        $i = 0;
        // Find how far the path is the same
        while (isset($from[$i]) && isset($to[$i])) {
            if ($from[$i] != $to[$i])
                break;
            $i++;
        }
        $j = count($from) - 1;
        // Add '..' until the path is the same
        while ($i <= $j) {
            if (!empty($from[$j]))
                $relpath .= '..' . DIRECTORY_SEPARATOR;
            $j--;
        }

        // Go to folder from where it starts differing
        while (isset($to[$i])) {
            if (!empty($to[$i]))
                $relpath .= $to[$i] . DIRECTORY_SEPARATOR;
            $i++;
        }

        // Strip last separator
        return substr($relpath, 0, -1) ?: ".";
    }