phpimagefilelaravel-5

Laravel Response::download() to show images in Laravel


So i figured out two possibility to store and show images in laravel 5. First way: to show images I have a route (e.g. loadFile/profil/{profilID}/main), which returns:

return Response::download($filepath)

My images are stored inside the storage folder, and therefore i can not access them via url, because this: www.domain.com/sotrage/files/... obviously does not work.

The other posibility would be to store the images inside the public folder and access them via their url.

My question: which of the two posibilitys i should use and what is best practice to store images in Laravel overall.


Solution

  • Image Upload

    $path = public_path('uploads/image/')
    $file_name = time() . "_" . Input::file('image')->getClientOriginalName();
    Input::file('image')->move($path, $file_name);
    

    Download Image

    $filepath = public_path('uploads/image/')."abc.jpg";
    return Response::download($filepath);