private file handling with laravel

File Handling using PHP
Change the maximum upload file size

problem statement

When you store files like pictures, videos, or other files, yo do not store them in the public folder but in a private folder that is not publicly accessible. Because only certain users should have access to the files.

How can you output multiple images from a private folder?

solution 1

To speed up you could do it via plain PHP (headers + read file):

 header('Content-Type: image/jpeg');
       header('Content-Length: ' . filesize($thumbnail));
       readfile($thumbnail);
       exit;

You can keep it to Laravel-style type code then something like this would do just fine

$headers = [
    'Content-Type' => 'image/jpeg', // if single type if not determine type
    'Content-Length' => filesize($thumbnail),
];
return response()->file($thumbnail, $headers);

You can optimize this with caching headers and any other flavor stuff.

File Handling using PHP
Change the maximum upload file size
en English
X
Scroll to Top