Sounds like there other non-image content being pushed to the browser.
I got something similar when sending PDF's to the browser.
Check the bottom of your controller for any spaces after the ?>
Also if you open the image directly then view its source, you should be able
to see the extra non-image content. If not you could try changing the
header('Content-type: image/gif'); to text for a run and see if you can spot
the non-image content.
Terre
________________________________
From: water [mailto:[email protected]]
Sent: Friday, March 13, 2009 1:34 PM
To: zend general
Subject: [fw-general] outputting image from controller private function
I was trying to output a an image from a controller's private function such
that:
http://host/app/controller/action/
would return an image.
I would need to reset the header's content type but I'm still having
problems (in browser error returned below). I've included some comments on
various things I tried. My code looks like this:
public function somethingAction(){
//ob_start();
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
if($this->_generate('play.html',$data)){
$this->_success();
}else{
$this->_failure();
//echo "failure<br/>";
}
}
private function _success(){
$file_name = "/data/sites/site/www/docs/fadmin/images/ok.gif";
if(ob_get_length()){
ob_end_flush();
exit;
}
/*
$this->_response->setHeader('Content-type', 'image/gif');
$this->_response->setHeader('Cache-Control', 'no-cache');
*/
header('Content-type: image/gif');
header("Cache-control: private, no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date
header("Pragma: no-cache");
echo fread(fopen($file_name, 'rb'), filesize($file_name));
/*
ob_end_flush();
$data = file_get_contents($file_name);
$this->_response->setBody($data);
*/
ob_end_flush();
}
The error I get in the browser is:
The image
"http://jt.agpublishdev.shockwave.com/fadmin/app/generator/play-with-friends
/" cannot be displayed, because it contains errors.
<http://jt.agpublishdev.shockwave.com/fadmin/app/generator/play-with-friends
/>
Any help with this would be greatlly appreciated.
thanks,
jonathan