I'm not sure if this will help you but it's how I display BLOB type
images.

Like Ryan said, you'll have a separate action in your controller
specifically for displaying your photo.

// PHOTOS CONTROLLER

function displayPhoto()
{
     $this->set('photo', $this->Photo->find('first',
array('conditions' => array($conditions))));
}

// display_photo.ctp

if(!empty($photo))
{
        Configure::write('debug', 0);
        header('Content-type:'.$photo['Photo']['type']);
        header('Content-length: '.$photo['Photo']['length']);
        echo $photo['Photo']['file'];
}

// Now to display your photo in your views

$html->tag('img', null, array(
                              'src' => Router::url(array(
                                                         'controller'
=> 'photos',
                                                         'action' => 
'displayPhoto/'.
$photo_id
                                                         )
                                                   ),
                              'style' => ''
                             )
          );

I hope that helps you out some, it may not be pretty but it's mine and
it works :)
You can nest the image tag inside of $html->link() to point to your
download function.

- Ed

On Jan 19, 9:09 am, euromark <dereurom...@googlemail.com> wrote:
> put this in your app helper:
>
>         /**
>          * display image tag from blob content
>          * enhancement for HtmlHelper
>          * 2010-11-22 ms
>          */
>         function imageFromBlob($text, $options = array()) {
>                 //<img alt="" src="data:image/png;base64,' . 
> $this->_getBase64() .
> '" /><br/>
>
>                 $text = 'data:image/png;base64,' . base64_encode($text);
>                 $image = sprintf($this->tags['image'], $text, 
> $this->_parseAttributes($options, null, '', ' '));
>
>                 return $image;
>         }
>
> $this->Html->imageFromBlob($blob);
>
> On 19 Jan., 06:22, Ryan Schmidt <google-2...@ryandesign.com> wrote:
>
>
>
>
>
>
>
> > On Jan 18, 2011, at 23:04, pinastro wrote:
>
> > > exactly , I am reading about Downloading the image ..
>
> > > and somehow I am able to display the image too...but it's RAW image
> > > CONTROLLER :::
>
> > > function download($id) {
> > >            Configure::write('debug', 0);
> > >            $file = $this->MyFile->findById($id);
> > >            $type= $file['MyFile']['type'];
> > >            $length = $file['MyFile']['size'];
> > >            $nam = $file['MyFile']['name'];
>
> > >            header('Content-type: $type');
> > >            header('Content-length: $length'); // some people reported 
> > > problems
> > > with this line (see the comments), commenting out this line helped in
> > > those cases
> > >            header('Content-Disposition: attachment; filename=$nam');
> > >            echo $file['MyFile']['data'];   ///WHEN I COMMENT THIS LINE 
> > > ....
> > > ONLY FILE LOCATION (database) is PRINTED
>
> > >            //$this->set(compact('file','nam'));
> > >            exit();
> > > }
>
> > > VIEW
>
> > > <?php
> > > echo "DISPLAY PINASTRO";
> > > header("Content-type: image/jpg");
> > > echo print_r((explode("/",$data['MyFile']['data'])));  //THIS WAS FOR
> > > TESTING PURPOSE THOUGH
> > > ?>
>
> > > not getting how will i use <IMG> tag ???
>
> > Read what I wrote again. You'll have two actions in your controller. One, 
> > this download action you've shown us, does nothing other than send the PNG 
> > to the browser. The second one will show a normal CakePHP ctp view file, 
> > and in that view, you'll create an img tag, just as you would to display 
> > any other static image, except that its src (I think I wrote href before 
> > but I meant src) will point not to a static file on disk but to the URL of 
> > your download action (i.e. "$this->link(array('action' => 'download', 
> > ...))").
>
> > Try getting the download action working first, so that when you call it up 
> > in the browser, it displays the image by itself. If it's not working, maybe 
> > read about media views, which handle a lot of this header business for you.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to