Make sure you are setting headers that match the type of image data being
stored.
Here's a controller i've used in the past for displaying image data. This
particular example gets its data from a file on the filesystem, but the same
would hold true for data from the database.
One thing to note:
Watch your closing tags. Worst case, make sure there is no trailing
whitespace or newlines. Best case, just omit the closing tag completely.
Additional whitespace can cause issues with the image data being rendered.
Hope this helps!
<?php
class ImageController extends Zend_Controller_Action
{
public function indexAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->ViewRenderer->setNoRender();
$file = '/path/to/file';
$info = getimagesize($file);
$mimeType = $info['mime'];
$size = filesize($file);
$data = file_get_contents($file);
$response = $this->getResponse();
$response->setHeader('Content-Type', $mimeType, true);
$response->setHeader('Content-Length', $size, true);
$response->setBody($data);
$response->sendResponse();
die();
}
}
On Wed, Jan 28, 2009 at 9:13 AM, maxarbos <[email protected]> wrote:
>
> Thank you. I am now able to get the file to upload, but now stuck as to how
> to get it to display within ZF.
>
> When I make the call to the code to show the image, I am just getting the
> characters of the source of the image and not the image itself. I used to
> do
> something like this when I was able to call a specific page that sent
> headers and such, but with ZF and Ajax calls, it doesnt seem to work the
> same.
>
> Is there something I am missing/forgetting to get the image to display?
>
> Thank you.
>
>
>
> thomasW wrote:
> >
> > Look at my blog.
> > There is an example for file uploads.
> >
> http://www.thomasweidner.com/flatpress/2008/11/01/file-transfer-hashing-and-other-news/
> >
> > Greetings
> > Thomas Weidner, I18N Team Leader, Zend Framework
> > http://www.thomasweidner.com
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Zend_Form---Zend_File-Upload-to-DB-not-working-tp21693984p21707673.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>
--
Michael Crumm
[email protected]