MCPcopy Create free account
hub / github.com/error311/FileRise / fr_detect_base_path

Function fr_detect_base_path

config/config.php:565–597  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

563}
564
565function fr_detect_base_path()
566{
567 // 1) Explicit env override
568 $env = getenv('FR_BASE_PATH');
569 if ($env !== false && trim((string)$env) !== '') {
570 return fr_normalize_base_path($env);
571 }
572
573 // 2) Reverse proxies often provide this
574 $xfp = $_SERVER['HTTP_X_FORWARDED_PREFIX'] ?? '';
575 if (is_string($xfp) && trim($xfp) !== '') {
576 return fr_normalize_base_path($xfp);
577 }
578
579 // 3) If deployed in a real subdirectory (not stripped by proxy),
580 // SCRIPT_NAME/REQUEST_URI will include the prefix (e.g. /fr/api/...).
581 $candidates = [];
582 if (!empty($_SERVER['SCRIPT_NAME']) && is_string($_SERVER['SCRIPT_NAME'])) $candidates[] = $_SERVER['SCRIPT_NAME'];
583 if (!empty($_SERVER['REQUEST_URI']) && is_string($_SERVER['REQUEST_URI'])) {
584 $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
585 if (is_string($path) && $path !== '') $candidates[] = $path;
586 }
587
588 foreach ($candidates as $p) {
589 if (preg_match('~^(.*)/api(?:/|\\.php$)~i', $p, $m)) return fr_normalize_base_path($m[1]);
590 if (preg_match('~^(.*)/webdav\\.php$~i', $p, $m)) return fr_normalize_base_path($m[1]);
591 if (preg_match('~^(.*)/index\\.html$~i', $p, $m)) return fr_normalize_base_path($m[1]);
592 if (preg_match('~^(.*)/portal-login\\.html$~i', $p, $m)) return fr_normalize_base_path($m[1]);
593 if (preg_match('~^(.*)/portal\\.html$~i', $p, $m)) return fr_normalize_base_path($m[1]);
594 }
595
596 return '';
597}
598
599if (!defined('FR_BASE_PATH')) {
600 define('FR_BASE_PATH', fr_detect_base_path());

Callers 1

config.phpFile · 0.85

Calls 1

fr_normalize_base_pathFunction · 0.85

Tested by

no test coverage detected