Исправлена проблема при скачивании прикреплённых файлов или просмотра картинок, когда название было на Русском.
71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
|
|
// Обработка статических файлов
|
|
function routing_static_files() {
|
|
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
|
|
$path = parse_url($requestUri, PHP_URL_PATH);
|
|
$path = urldecode($path); // декодируем кириллицу из URL
|
|
|
|
// Отдача файлов из /public/ (принудительное скачивание)
|
|
if (strpos($path, '/public/') === 0) {
|
|
$file = dirname(dirname(__DIR__)) . $path;
|
|
if (is_file($file)) {
|
|
$filename = basename($file);
|
|
$filename_encoded = rawurlencode($filename);
|
|
|
|
header('Content-Type: application/octet-stream');
|
|
header('Content-Length: ' . filesize($file));
|
|
// RFC 5987: filename* для кириллицы, filename для fallback
|
|
header("Content-Disposition: attachment; filename=\"$filename\"; filename*=UTF-8''$filename_encoded");
|
|
readfile($file);
|
|
exit;
|
|
}
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
|
|
// Игнорирование favicon и прочих статических запросов
|
|
if (preg_match('/\.(ico|css|js|woff|woff2|ttf|eot)$/i', $requestUri)) {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// Проверка авторизации для API
|
|
function check_ApiAuth($publicActions = []) {
|
|
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
|
|
|
|
if (strpos($requestUri, '/api/') !== false) {
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|
$action = $input['action'] ?? null;
|
|
|
|
// Публичные действия — без авторизации
|
|
|
|
if (!in_array($action, $publicActions)) {
|
|
$account = new Account();
|
|
$result = $account->check_session($_COOKIE['session'] ?? null);
|
|
if (!$result['success']) {
|
|
RestApi::response($result, 403);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Функция роутинга API
|
|
function handleRouting($routes = []) {
|
|
|
|
$request = $_SERVER['REQUEST_URI'];
|
|
$path = parse_url($request, PHP_URL_PATH);
|
|
|
|
if (isset($routes[$path])) {
|
|
|
|
$file_path = $routes[$path];
|
|
global $_POST, $_FILES, $_SERVER, $_GET;
|
|
include $file_path;
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|