Кирилица в файлах
Исправлена проблема при скачивании прикреплённых файлов или просмотра картинок, когда название было на Русском.
This commit is contained in:
@@ -4,14 +4,19 @@
|
|||||||
function routing_static_files() {
|
function routing_static_files() {
|
||||||
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
|
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
|
||||||
$path = parse_url($requestUri, PHP_URL_PATH);
|
$path = parse_url($requestUri, PHP_URL_PATH);
|
||||||
|
$path = urldecode($path); // декодируем кириллицу из URL
|
||||||
|
|
||||||
// Отдача файлов из /public/ (принудительное скачивание)
|
// Отдача файлов из /public/ (принудительное скачивание)
|
||||||
if (strpos($path, '/public/') === 0) {
|
if (strpos($path, '/public/') === 0) {
|
||||||
$file = dirname(dirname(__DIR__)) . $path;
|
$file = dirname(dirname(__DIR__)) . $path;
|
||||||
if (is_file($file)) {
|
if (is_file($file)) {
|
||||||
|
$filename = basename($file);
|
||||||
|
$filename_encoded = rawurlencode($filename);
|
||||||
|
|
||||||
header('Content-Type: application/octet-stream');
|
header('Content-Type: application/octet-stream');
|
||||||
header('Content-Length: ' . filesize($file));
|
header('Content-Length: ' . filesize($file));
|
||||||
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
|
// RFC 5987: filename* для кириллицы, filename для fallback
|
||||||
|
header("Content-Disposition: attachment; filename=\"$filename\"; filename*=UTF-8''$filename_encoded");
|
||||||
readfile($file);
|
readfile($file);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user