php - Displaying image directly in browser using zend framework -


i trying display image using zend framework in directly browser. can display png format.

here code works fine when try access png image , displays image in browser.

// disable layout $this->_helper->layout->disablelayout();  $file = 'http://framework.zend.com/images/poweredby_zf_4lightbg.png';  $logo = file_get_contents($file);   $type = 'image/png';  $response = $this->getfrontcontroller()->getresponse();  $response->setheader('content-type', $type, true); $response->setheader('content-length', count($logo), true); $response->setheader('content-transfer-encoding', 'binary', true); $response->setheader('cache-control', 'max-age=3600, must-revalidate', true); $response->setbody($logo);  $response->sendresponse();  exit;  

again: above code works fine , displays image in browser correctly when try jpeg/jpg image give me message:

the image “http://localhost/zfproject/activity/share/image” cannot displayed because contains errors.

here code used jpeg/jpg image type

// disable view ... , perhaps layout $this->_helper->layout->disablelayout();  $file = 'http://localhost/zfproject/public/user/15/0015_19aa.jpg?c=5090';  $logo = file_get_contents($file);   $type = 'image/jpg';  $response = $this->getfrontcontroller()->getresponse();  $response->setheader('content-type', $type, true); $response->setheader('content-length', count($logo), true); $response->setheader('content-transfer-encoding', 'binary', true); $response->setheader('cache-control', 'max-age=3600, must-revalidate', true); $response->setbody($logo);  $response->sendresponse();  exit;  

i not know may doing wrong, have tried type 'image/jpeg' doesn't work.

please advise.

thank in advance.

try this:

$this->_helper->layout->disablelayout();  $file = 'http://localhost/zfproject/public/user/15/0015_19aa.jpg?c=5090';  $logo = file_get_contents($file);   $type = 'image/jpg';  $response = $this->getfrontcontroller()->getresponse();  $response->setheader('content-type', $type, true); $response->setheader('content-transfer-encoding', 'binary', true); $response->setheader('cache-control', 'max-age=3600, must-revalidate', true); $response->setbody($logo);  $response->sendresponse();  exit;  

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -