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!
source share