41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
$requestUri = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
|
|
$uri = $requestUri;
|
|
$basePath = trim((string) getenv('FOTOBOX_BASE_PATH'));
|
|
|
|
if ($basePath !== '' && $basePath !== '/') {
|
|
$basePath = '/' . trim($basePath, '/');
|
|
|
|
if (str_starts_with($uri, $basePath)) {
|
|
$uri = substr($uri, strlen($basePath)) ?: '/';
|
|
}
|
|
}
|
|
|
|
$resolvedFile = __DIR__ . '/' . ltrim($uri, '/');
|
|
if ($uri !== '/' && is_file($resolvedFile)) {
|
|
if ($uri === $requestUri) {
|
|
return false;
|
|
}
|
|
|
|
$extension = strtolower(pathinfo($resolvedFile, PATHINFO_EXTENSION));
|
|
$mimeTypes = [
|
|
'css' => 'text/css; charset=UTF-8',
|
|
'js' => 'application/javascript; charset=UTF-8',
|
|
'svg' => 'image/svg+xml',
|
|
'png' => 'image/png',
|
|
'jpg' => 'image/jpeg',
|
|
'jpeg' => 'image/jpeg',
|
|
'webp' => 'image/webp',
|
|
];
|
|
|
|
header('Content-Type: ' . ($mimeTypes[$extension] ?? 'application/octet-stream'));
|
|
header('Content-Length: ' . (string) filesize($resolvedFile));
|
|
readfile($resolvedFile);
|
|
return true;
|
|
}
|
|
|
|
require __DIR__ . '/index.php';
|