fix: Behebe nicht angezeigte Icons mit PHP-Proxy

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
torsten 2026-10-04 07:24:32 +02:00
parent fd016287a6
commit c6e5a8b2b6
4 changed files with 52 additions and 6 deletions

46
public/image.php Normal file
View file

@ -0,0 +1,46 @@
<?php
// Simpler Bild-Proxy, um mögliche Server-Konfigurationsprobleme für statische Dateien zu umgehen.
$file = $_GET['file'] ?? '';
// Sicherheit: Verhindere Directory Traversal und erlaube nur Dateien aus bestimmten Verzeichnissen.
if (empty($file) || strpos($file, '..') !== false || substr($file, 0, 6) !== 'icons/') {
http_response_code(400);
echo "Bad Request";
exit;
}
$baseDir = __DIR__; // Dies ist das /public Verzeichnis
$filePath = $baseDir . '/' . $file;
// Sicherheit: Stelle sicher, dass der endgültige Pfad innerhalb des erwarteten Verzeichnisses liegt.
$realBasePath = realpath($baseDir . '/icons');
$realFilePath = realpath($filePath);
if ($realBasePath === false || $realFilePath === false || strpos($realFilePath, $realBasePath) !== 0) {
http_response_code(403);
echo "Forbidden";
exit;
}
if (!file_exists($filePath)) {
http_response_code(404);
echo "Not Found";
exit;
}
// MIME-Typ basierend auf der Dateiendung bestimmen
$extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
$mimeTypes = [
'png' => 'image/png',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'gif' => 'image/gif',
'svg' => 'image/svg+xml',
];
$mimeType = $mimeTypes[$extension] ?? 'application/octet-stream';
header('Content-Type: ' . $mimeType);
readfile($filePath);