I agree with Brian. Using exit is bad style (if you care) disabling
rendering is nicer and lets Cake clean up after the controller has
run.

Your code looks ok. It should display (or force-download) a file for
you. If you see crap, or nothing at all, than check that $type really
is a mime-type and that the binary data really is an image. The first
can of-course be checked by just debugging out the variable to see if
it really reads "image/jpg" and just just "jpg" or something like
that. The last part can be done by reading it and dumping the data to
a file and checking it.

One thing I have noticed is that sometimes you can help the browser
along by setting the src to /path/to/image/12/filename.jpg or
something like it. Saying that is is a jpeg in the filename is good
when the header has no filename specified. (you only set content type)

You might try: header("Content-Transfer-Encoding: binary") or any
number of "good" file-transfer headers.

/Martin


On Mar 17, 5:00 pm, brian <[email protected]> wrote:
> On Tue, Mar 17, 2009 at 2:04 AM, Rufus <[email protected]> wrote:
>
> > Hi,
>
> > I have going through all the discussions looking for an easy way to
> > show a blob in a view. I have got to what I think is the most simple
> > way of doing it.
>
> > Controller:
>
> >  function display($id) {
> >    Configure::write('debug', 0);
> >    $file = $this->Image->findById($id);
> >    $type = $file['Image']['type'];
> >    $data = base64_decode($file['Image']['image']);
> >    header("Content-type: $type");
> >    echo "$data";
> >    exit();
> >  }
>
> > View:
>
> > echo '<img src="/images/display/'.$image['Image']['id'].'" title="'.
> > $image['Image']['name'].'" alt="'.$image['Image']['name'].'" />';
>
> > All I get in FF is the alt tag and in IE I get the gobligook.
>
> It looks like you need to set $autoRender & $autoLayout = false
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to