public function adjust_path($mroot, $fname) { $result = null; if (file_exists($fname->filename)) { $result = pathDiff($fname->filename, $mroot); } else { if (file_exists($mroot . $fname->filename) || file_exists($mroot . DIRECTORY_SEPARATOR . $fname->filename)) { $result = trim(toUrlPath($fname->filename), "/"); } } return $result; }
/** * Returns relative path from two directories with full path * * @param string $path1 * @param string $path2 * @return string */ function pathDiff($path1, $path2) { toUrlPath($path1); toUrlPath($path2); $result = ""; $bl2 = strlen($path2); $a = strpos($path1, $path2); if ($a !== false) { $result = trim(substr($path1, $bl2 + $a), '/'); } return $result; }