Re: Frustrated, puzzled and confused: outputting images from a databa se
| From: | David Otton | Date: | Wed, 13 Dec 2000 00:33:00 +0000 |
| Subject: | Re: Frustrated, puzzled and confused: outputting images from a databa se | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-29993@lists.php.net to get a copy of this message | ||
>On Wed, 13 Dec 2000, Jason Murray wrote:
>> I'm storing image data (either image/gif or image/[p]jpeg) (and its
>> mimetype) in a BLOB column of a MySQL database.
>> My problem is that when I pull the image data from the database, I'm
>> not sure what to do in order to output it. I've tried:
>>
>> <?
>> Header("Content-Type: image/gif");
>> echo $imagedata;
>> Exit();
>> ?>
>>
>> But this only seems to produce a broken image in a browser, and when
>> I look at it on a command line it *seems* to work. Please excuse crap
>> below:
This is a small script that generates a web bug. Works for me.
<? include("php_include.inc");
$gif =
"\107\111\106\70\71\141\1\0\1\0\200\0\0\377\377\377\377\377\377\41\37
1\4\1\0\0\1\0\54\0\0\0\0\1\0\1\0\0\2\2\104\1\0\73";
ob_start();
header("Content-type: image/gif");
echo($gif);
$buffer_contents = ob_get_contents();
$buffer_length = strlen($buffer_contents);
header("Content-Length: $buffer_length");
/* whatever you want to do goes here - make sure you don't print
anything! */
?>
The ob_start() etc. isn't strictly necessary, I just like to send a
Content-Length header.
If something like this works for you, is it possible that your image
is getting munged as it comes out of the database?
Or that PHP is outputting an error message instead of your image?
(Remove the Content-Type header and see what you get).
djo