Calculate the relative path from $from to $to
Derived from https://stackoverflow.com/a/2638272/

@param $from
@param $to
@return string
967932
private static function getRelativePath($from, $to)
    {
        // some compatibility fixes for Windows paths
        $from = is_dir($from) ? rtrim($from, '\/') . DIRECTORY_SEPARATOR : $from;
        $to = is_dir($to) ? rtrim($to, '\/') . DIRECTORY_SEPARATOR : $to;
        $from = str_replace('\\', DIRECTORY_SEPARATOR, $from);
        $to = str_replace('\\', DIRECTORY_SEPARATOR, $to);

        $from = explode(DIRECTORY_SEPARATOR, $from);
        $to = explode(DIRECTORY_SEPARATOR, $to);
        $relPath = $to;

        $relPath = self::calculateRelativePath($from, $to, $relPath);
        $relPath = implode(DIRECTORY_SEPARATOR, $relPath);
        $relPath = self::removePointerToCurrentDir($relPath);
        return $relPath;
    }
605997
public function copyFolder( $from, $to )
	{
		$this->connection->checkConnection();
		$this->createFolder( $to );
		$reader	= new Net_FTP_Reader( $this->connection );
		$list	= $reader->getList( $from, TRUE );
		foreach( $list as $entry )
		{
			if( $entry['isdir'] )
				$this->createFolder( $to."/".$entry['name'] );
			else
				$this->copyFile( $from."/".$entry['name'], $to."/".$entry['name'] );
		}
		return TRUE;
	}
230326
private function resolveTo($to, $from)
    {
        if (is_string($to)) {
            $to = strtolower($to);
        }

        if ($to === 'down') {
            $to = $this->versionCollection->getPreviousVersion($from);
        }

        if ($to === 'up') {
            $to = $this->versionCollection->getNextVersion($from);
        }

        if ($to === 'bottom') {
            $to = 0;
        }

        if ($to === 'top' || null === $to) {
            $to = $this->versionCollection->getLatestVersion();
        }

        if (0 !== $to && false === strtotime($to)) {
            throw new MigratorException(sprintf(
                'Unknown migration action "%s". Known actions: "%s"',
                $to,
                implode('", "', $this->actions)
            ));
        }

        if (0 !== $to && !$this->versionCollection->has($to)) {
            throw new MigratorException(sprintf(
                'Unknown version "%s"', $to
            ));
        }

        return $to;
    }
1165670
public static function dateDiff($from, $to = null)
    {
        if (!$to) {
            $to = $from;
            $from = date("d/m/Y");
        }

        if (!$dateFrom = static::date("U", $from)) {
            return;
        }

        if (!$dateTo = static::date("U", $to)) {
            return;
        }

        $diff = $dateTo - $dateFrom;
        $days = round($diff / 86400);

        return $days;
    }
482560
public static function download($from, $to): bool
    {
        /**
         * @var bool|resource $fromStream
         */
        $fromStream = File::open($from);

        if (!is_resource($fromStream))
        {
            throw new NotFound\Path('Stream `' . $from . '` not found');
        }

        if (!File::real($to) && !File::touch($to))
        {
            throw new Exceptions\PermissionDenied('File `' . $to . '`');
        }

        File::put($to, $fromStream);

        return File::close($fromStream);
    }
19961
public function copyTo(FileNode $from, FileNode $to)
    {
        $mountManager = new MountManager([
            'from' => $from->getFilesystem(),
            'to'   => $to->getFilesystem(),
        ]);

        $this->log(LogLevel::INFO, "Copying file from: '{from}', to: '{to}'", [
            'from' => $from,
            'to'   => $to,
        ]);
        if (!$mountManager->copy('from://' . $from->getPath(), 'to://' . $to->getPath())) {
            throw new TransferFailedException($from, $to);
        }

        return $to;
    }
681335
protected function publishItem($from, $to)
    {
        if ($this->files->isFile($from)) {
            return $this->publishFile($from, $to);
        } elseif ($this->files->isDirectory($from)) {
            return $this->publishDirectory($from, $to);
        }

        $this->error("Can't locate path: <{$from}>");
    }
829628
public function ireplace($from, $to)
    {
        if (\is_callable($to)) {
            $to = $to($from, $this->string);
        }

        $this->string = \str_ireplace($from, $to, $this->string);
        return $this;
    }
651603
public static function supports($from, $to) {
        // This is not a one-liner because of php 5.6.
        $imports = self::$imports;
        $exports = self::$exports;
        return isset($imports[$from]) && isset($exports[$to]);
    }
43723
public function distanceVincenty(Position $from, Position $to): Distance
    {
        $lat1 = $from->latitude();
        $lng1 = $from->longitude();
        $lat2 = $to->latitude();
        $lng2 = $to->longitude();

        $a = Earth::SEMI_MAJOR_AXIS;
        $b = Earth::SEMI_MINOR_AXIS;
        $f = Earth::FLATTENING;

        $L = \deg2rad($lng2 - $lng1);
        $U1 = \atan((1 - $f) * \tan(\deg2rad($lat1)));
        $U2 = \atan((1 - $f) * \tan(\deg2rad($lat2)));

        $sinU1 = \sin($U1);
        $cosU1 = \cos($U1);
        $sinU2 = \sin($U2);
        $cosU2 = \cos($U2);

        $lambda = $L;
        $iterLimit = 100;

        do {
            $sinLambda = \sin($lambda);
            $cosLambda = \cos($lambda);
            $sinSigma = \sqrt(($cosU2 * $sinLambda) * ($cosU2 * $sinLambda) +
                ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda) *
                ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda));

            if (0.0 === $sinSigma) {
                return new Distance(0); // co-incident points
            }

            $cosSigma = $sinU1 * $sinU2 + $cosU1 * $cosU2 * $cosLambda;
            $sigma = \atan2($sinSigma, $cosSigma);
            $sinAlpha = $cosU1 * $cosU2 * $sinLambda / $sinSigma;
            $cosSqAlpha = (float) 1 - $sinAlpha * $sinAlpha;

            if (0.0 !== $cosSqAlpha) {
                $cos2SigmaM = $cosSigma - 2 * $sinU1 * $sinU2 / $cosSqAlpha;
            } else {
                $cos2SigmaM = 0.0; // Equatorial line
            }

            $C = $f / 16 * $cosSqAlpha * (4 + $f * (4 - 3 * $cosSqAlpha));
            $lambdaP = $lambda;
            $lambda = $L + (1 - $C) * $f * $sinAlpha *
                ($sigma + $C * $sinSigma * ($cos2SigmaM + $C * $cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM)));
        } while (\abs($lambda - $lambdaP) > 1e-12 && --$iterLimit > 0);

        if ($iterLimit === 0) {
            throw new Exception\RuntimeException('Vincenty formula failed to converge.');
        }

        $uSq = $cosSqAlpha * ($a * $a - $b * $b) / ($b * $b);
        $A = 1 + $uSq / 16384 * (4096 + $uSq * (-768 + $uSq * (320 - 175 * $uSq)));
        $B = $uSq / 1024 * (256 + $uSq * (-128 + $uSq * (74 - 47 * $uSq)));
        $deltaSigma = $B * $sinSigma * ($cos2SigmaM + $B / 4 * ($cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM) -
                    $B / 6 * $cos2SigmaM * (-3 + 4 * $sinSigma * $sinSigma) * (-3 + 4 * $cos2SigmaM * $cos2SigmaM)));
        $s = $b * $A * ($sigma - $deltaSigma);

        return new Distance($s);
    }
1248235
public function rename($from, $to): bool
    {
        $key = $this->search($from);

        if (\is_null($key)) {
            return false;
        }

        $this->items[$key] = $this->getKeyword($to)->getSlug();

        return true;
    }
680197
public function moveDataFile($from, $to)
    {
        if (str_contains($from, '*.')) {
            $this->moveFilesWildcard($from, $to);

            return;
        }

        if (file_exists($from = $this->dataDir($from))) {
            $this->mkDir(dirname($to = $this->dataDir($to)));

            rename($from, $to);
        }
    }
268340
public function alias($from, $to = null)
	{
		if (is_array($from))
		{
			$this->aliases = array_merge($this->aliases, $from);

			return $this;
		}

		$this->aliases[$from] = $to;
		$this->cache->set($from, $to);
	}
1172711
public static function DateRangeDiff(string $from, string $to)
    {
        $date_Range = new \Phunc\DateRange\DateRange();
        $date_Range->fillFromString($from, $to);
        $date_Range->getFrom()->hour(0)->minute(0)->second(0);
        $date_Range->getTo()->hour(24); //->minute(59)->second(59);
        return $date_Range->diffInDays();
    }
1044503
public function copy($from, $to)
    {
        $pathFrom = $this->pathRoot.ltrim($from, "/");
        $pathTo   = $this->pathRoot.ltrim($to, "/");

        if (is_dir($pathFrom)) {
            return $this->copyDir($pathFrom, $pathTo);
        } else {
            return $this->copyFile($pathFrom, $pathTo);
        }
    }
93445
protected function dateDiffNoDST(\DateTime $from, \DateTime $to)
    {
        $fromUTC = new \DateTime($from->format('Y-m-d\TH:i:s+00:00'));
        $toUTC = new \DateTime($to->format('Y-m-d\TH:i:s+00:00'));

        return $fromUTC->diff($toUTC);
    }
22623
public function findByFrom($from)
    {
        if ($from[0] != '/') {
            $from = "/$from";
        }
        $from = rtrim($from, '?');

        if (strpos($from, '?') !== false) {
            list($base, $querystring) = explode('?', strtolower($from), 2);
        } else {
            $base = $from;
            $querystring = null;
        }

        $filter = array(
            'FromBase' => $base,
        );

        if ($querystring) {
            $filter['FromQuerystring'] = $querystring;
        }

        return RedirectedURL::get()->filter($filter)->first();
    }