Reputation: 169
I am making a image uploading function for a website using Laravel 5.1. Because of security problems, I want to store those images in /storage/app
folder, instead of /public
. Image's URL, for example:
/storage/app/images/<image_name>
In order to get image from /storage/app
, I set up a specific route for this:
http://app.com/image/<image_name>
To point image requests to /storage
:
Route::controllers([
'image' => 'Frontend\ImageController',
]);
In ImageController
, here is the code to create 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, after using this route to retrieve images, I can't display them in my view. There were no 404, 500 or any error status codes, request URL was it supposed to be, but it just showed a broken image icon. Is there anything wrong with my code?
Thank you!
Upvotes: 5
Views: 3660
Reputation: 169
Sorry guys, a php scripts in my /config
folder has leading space, and that caused the http response failed @@ Such a nonsense mistake... Thank you all for your help!
Upvotes: 0