Fix file type

This commit is contained in:
Julian Prieber 2024-09-19 12:52:46 +02:00
parent 1abab3fd40
commit 74eeb1a832
1 changed files with 28 additions and 8 deletions

View File

@ -6,6 +6,7 @@ use App\Models\LinkType;
use App\Models\Link; use App\Models\Link;
use App\Models\Button; use App\Models\Button;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\File;
class LinkTypeViewController extends Controller class LinkTypeViewController extends Controller
{ {
@ -77,6 +78,25 @@ class LinkTypeViewController extends Controller
return response('File not found', Response::HTTP_NOT_FOUND); return response('File not found', Response::HTTP_NOT_FOUND);
} }
return response()->file($fullPath); // Map file extensions to MIME types
$mimeTypes = [
'js' => 'application/javascript',
'css' => 'text/css',
'img' => 'image/png',
'svg' => 'image/svg+xml',
'gif' => 'image/gif',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'mp4' => 'video/mp4',
'mp3' => 'audio/mpeg',
];
// Determine the MIME type using the mapping
$mimeType = $mimeTypes[$extension] ?? 'application/octet-stream';
return response()->file($fullPath, [
'Content-Type' => $mimeType
]);
} }
} }