Laravel 5.1 - Display Images Stored In Storage Folder

- 1 answer

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:


In order to get image from /storage/app, I set up a specific route for this:<image_name>

To point image requests to /storage:

    '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!



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!