46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?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);
|