What is the correct way to restrict access to large files in laravel
I am wondering what the best way to restrict access to large files in laravel is. I have seen this https://stackoverflow.com/questions/16262727/what-is-the-best-way-to-restrict-access-in-laravel and it doesn't fit my use case because I need to restrict LARGE files. This is what I have in the appropriate route right now ```php Route::get('/restricted/{page}', function($page) { $content_types = [ ".aac" => "audio/aac", ".abw" => "application/x-abiword", ".arc" => "application/x-freearc", ".avi" => "video/x-msvideo", ".azw" => "application/vnd.amazon.ebook", ".bin" => "application/octet-stream", ".bmp" => "image/bmp", ".bz" => "application/x-bzip", ".bz2" => "application/x-bzip2", ".csh" => "application/x-csh", ".css" => "text/css", ".csv" => "text/csv", ".doc" => "application/msword", ... ]; if (!preg_match("/.*\..*/",$page)) { $page .= "/index.htm"; } if (file_exists(app_path('StaticPages/' . $page))) { $captured = array(); preg_match("/^.*(\..*)$/", $page,$captured); $type = $content_types[$captured[1]] ?? 'text/plain'; return response(File::get(app_path('StaticPages/') . $page))->header('Content-Type', $type); } else { return abort(404); } })->middleware(['auth','admin-verified'])->name('static-pages')->where('page', '.*'); ``` For background, my client has a static html site that he needs to be restricted by an authentication system. I have that built, but the problem with what I have right now, is that about half of the large files (he has like 50 images on some pages) make 500 errors. It is different files each time though, so I'm pretty sure that it has to do with memory. Also I have alowed php to have unlimited memory. Any help would be appreciated. Thanks.