php - How to Return a Text with an Image in Laravel 4 -


i'm working on laravel 4 application , wrote method called show() inside controller gets id route , makes array of elements database, these elements returned image. can return image without text using response::make() , header, if bind data can't read image.

i tried :

public function show($id){      $onlinead = onlineads::where('id', $id)->get(array('title', 'short_description', 'full_description'));      $filename = onlineads::find($id)->image;     $path = 'app/storage/uploads/mobile/' . $filename;      return response::json([         "data" => $onlinead,          "image"=> base64_encode(file::get($path))     ]); } 

this returns data perfectly, image returns unreadable text instead. suggestions?

i assume don't in view, meant "code handles displaying of image"

before inserting in src attribute, should format image payload properly.
change bit of code so:

return response::json([     "data" => $onlinead,      "image"=> 'data:image/png;base64,' . base64_encode(file::get($path)) ]); 

to include data , mime type , base64 after comma.

modify mime type accordingly, image/png, image/jpg, etc.

also, see reference how display base64 images in html?


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -