In this article we are going to discuss how you can view or download files from the storage. If you want to upload some files to storage you can view this tutorial
You can add the following code to your routes\web.php file
Route::get('view', 'UploadController@view'); Route::get('get/{filename}', 'UploadController@getFile')->name('getfile');
You have the getFile
action in your UploadController
. So you can add the following code to it
function getFile($filename){ $file=Storage::disk('public')->get($filename); return (new Response($file, 200)) ->header('Content-Type', 'image/jpeg'); }
You get the file from the storage by giving the file name and get the response with correct content type
You have the view
action also. You can add the following code to it
$files = Storage::files("public"); $images=array(); foreach ($files as $key => $value) { $value= str_replace("public/","",$value); array_push($images,$value); } return view('display', ['images' => $images]);
You get the image files from the public folder and extract the name of these files and you pass them to your view
Finally you can create a view display.blade.php
in resources\view
folder
@foreach($images as $image)@endforeach![]()