Your ImageController action worked on my machine, the only thing I changed was the image; I provided the absolute path to a png on my server. The image was provided when I requestedCode:http://thedomain.com/controllername/image
Hi all,
I tried from long time to return an image content from an action :
HTML :
Action :Code:<img src="user/loadavatar" />
When I called my action : http://localhost/skybook/image/imageCode:class ImageController extends Zend_Controller_Action { function imageAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $image = file_get_contents("test.png"); $this->getResponse()->clearBody (); $this->getResponse()->setHeader('Content-Type', 'image/png'); $this->getResponse()->setBody($image); } }
-> Firefox display : "Image cannot be displayed because it contains errors"
If I try to put in a simple file test.php :
It works !!Code:<?php header("Content-Type: image/png"); echo file_get_contents('test.png'); ?>
I think something is added to my content when I want to pass via an action.....
Help !!!
Jo
Your ImageController action worked on my machine, the only thing I changed was the image; I provided the absolute path to a png on my server. The image was provided when I requestedCode:http://thedomain.com/controllername/image
Last edited by rbroen; 06-28-2010 at 09:24 AM.
:s
What can I do now, I am sure that the image I readed correctly because I can see the content but impossible to view the image....Do you think my bootstraap could be the cause ? (it could add some stupid things)......
Thx
try a fresh zf project (like I did)
try a different png file
take a look at your apache error.log (an post it back here)
On clean project & different image & no error in apache log :
Firefox put : http://localhost/test/image/imageCode:class ImageController extends Zend_Controller_Action { function imageAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $image = file_get_contents("test.jpg"); $this->getResponse()->clearBody (); $this->getResponse()->clearAllHeaders(); $this->getResponse()->setHeader('Content-Type', 'image/jpg',true); $this->getResponse()->setHeader('Cache-Control', 'public'); $this->getResponse()->setBody($image); } }
IE put the content of the image, if I tried to save the content in jpg image file I cannot open it.....
Why it works if I call a simple php file but via an action it doesn't ?
Last edited by joatack; 06-29-2010 at 09:36 AM.
I compared the original image and the generated image and there is 2 differences :
-> a small hexa code is added at the begining of content (0D 0A.......)
-> a smal hexa code is removed at the end of content (........00 3B
)
Why when I use an action, the content of the image is modified ?
Resolved, it was the empty line in my bootstraap, index and helpers.....
Don't use the end tag (?>) and remove all empty line at the end of files !
thx for help !