I am trying to return an image, however I cannot get the 'Content-type' to set and when I navigate to the route it is just symbols. Here is my code:
public function show(Item $item, $img_id){
return $item->images[$img_id-1]->getImage();
}
public function getImage(){
$image_loc = storage_path().'/app/item_images/'.$this->item_slug.'/'.$this->image_number.'.jpg';
return response(readfile($image_loc))->header('Content-type', 'image/jpeg', true);
}
I cannot find why it is not working, so I would appreciate it if someone could help, thanks! :)
thomastkim said:
What does the readfile function do?
It's built into laravel and returns a file contents.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community