Hi, thanks for all the suggestions.  I tried using the proper headers,
and it's still not working.  Like I mentioned, using the correct
headers produces an image on the test.php script, but not for my
download action on Schoolpictures.

I also tried the $html->image helper mentioned in the article above
and that ended up producing no output.

I managed to get the two to produce the same binary output, but when
viewing source, the download action produces some white space, which I
think may be the source of the problem:

http://www.ignitenation.org/index.php/schoolpictures/download/6
http://www.ignitenation.org/test.php

On Jun 4, 1:13 am, Martin Westin <[email protected]> wrote:
> Don't forget the length header either. (Too many sites still output
> files of "unkown" size)
>
> header('Content-Length: '.mb_strlen($my_image_blob));
> header('Content-type: '.$my_image_contenttype);
>
> Even though a file from a blob probably isn't going to be "big" by
> today's standards, it is nice to let the browser know how much data is
> coming.
>
> On Jun 4, 3:34 am, brian <[email protected]> wrote:
>
> > You have to send the correct headers before echoing the data. Have a
> > look at this recent article at the Bakery about doing something
> > similar:
>
> >http://bakery.cakephp.org/articles/view/imagebehavior-best-from-datab...
>
> > On Wed, Jun 3, 2009 at 7:49 PM, Jon <[email protected]> wrote:
>
> > > Hi, I searched through the archives and didn't find a solution to this
> > > problem I'm encountering so hopefully someone here will know what it
> > > is.  I'm trying to get the contents (image) of a MySQL blob field and
> > > output it.  However, it won't display properly.
>
> > > I have modified my code so that it just echos the data that it
> > > retrieves from the database:
>
> > > function download($id = null) {
> > >        Configure::write('debug', 0);
> > >        if ($id != null) {
> > >                $pic = $this->Schoolpicture->findById($id);
> > >                echo $pic['Schoolpicture']['content'];
> > >        }
> > >        exit();
> > > }
>
> > > This produces the result shown here (for picture 6):
> > >http://www.ignitenation.org/index.php/schoolpictures/download/6
>
> > > I also have another test script that bypasses all the CakePHP
> > > structure.  It just retrieves the data and outputs it:
>
> > > <?php
> > > error_reporting(E_ALL);
> > > $my_table  = 'schoolpictures';
> > > $my_server = '----';
> > > $my_user   = '----';
> > > $my_pwd    = '----';
> > > $my_name   = '----';
> > > $my_link   = mysql_connect($my_server, $my_user, $my_pwd)
> > >  or exit('Could not connect (' . mysql_errno() . '): ' . mysql_error
> > > ());
> > > $my = mysql_select_db($my_name, $my_link)
> > >  or exit('Could not select database (' . mysql_errno() . '): ' .
> > > mysql_error());
> > > $row = mysql_fetch_array(mysql_query("SELECT content FROM $my_table
> > > where id=6"));
> > > print $row['content'];
> > > ?>
>
> > > You'll see that the result (for the same image 6) found at the
> > > following link looks quite different:http://www.ignitenation.org/test.php
>
> > > If you do a view source, the first link has some whitespace before the
> > > data whereas this one does not.  Also, it looks like the data is
> > > encoded differently.  If I add the proper header (Content-type: image/
> > > gif), test.php will display my image properly.  I suspect that the
> > > whitespace and/or the different encoding is the source of the problem,
> > > but I have no idea what could be causing that.
>
> > > Thanks for reading this long post and for any insight that you might
> > > be able to provide on this issue!
--~--~---------~--~----~------------~-------~--~----~
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