php - How to include the image from byte array with other content in codeigniter? -


i trying make profile view of user using image byte array. have rendered image, have problem including image other profile content, because of header('content-type: image/png') takes whole file image. how resolve problem?

$myarray = implode('', array_map(function($e) {     return pack("c*", $e); }, $image)); if      (substr($myarray, 0, 4) == "\x89png") header('content-type: image/png'); else if (substr($myarray, 0, 2) == "\xff\xd8") header('content-type: image/jpeg'); else if (substr($myarray, 0, 4) == "gif8") header('content-type: image/gif'); echo $myarray; 

you can't serve raw image data part of html document.

there couple of ways can go serving image:

  1. base64 encode , embed in img src. see thread example.
  2. save image file , serve other image.

#2 had advantage of allowing image cached browser. if images large try work out way save file.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -