Laravel 5.1 - Display Images Stored In Storage Folder
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!
Answer
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!
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?