Laravel 5.1 - Displaying images stored in the Storage folder

I am making an image upload function for a website using Laravel 5.1. Due to security issues, I want to save these images in the /storage/app folder instead of /public . Image URL, for example:

 /storage/app/images/<image_name> 

To get the image from /storage/app , I set a specific route for this:

 http://app.com/image/<image_name> 

To request image requests to /storage :

 Route::controllers([ 'image' => 'Frontend\ImageController', ]); 

In ImageController here is the code to create the response:

 public function missingMethod($filename = []) { if (is_array($filename)) { $filename = implode('/', $filename); } // storage_path('app') - path to /storage/app folder $path = storage_path('app') . '/' . $filename; $file = \File::get($path); $type = \File::mimeType($path); return \Response::make($file,200) ->header("Content-Type", $type); } 

My problem is that after using this route to retrieve the images, I cannot display them in my view. There were no 404, 500 or any error status codes, the request URL should have been, but it just showed a broken image icon. Is there something wrong with my code?

Thanks!

+5
source share
1 answer

Sorry guys, php scripts in my /config folder have a leading place, and this caused an HTTP @@ response to be rejected. Such a mistake of nonsense ... Thank you for your help!

0
source

Source: https://habr.com/ru/post/1240494/


All Articles