retrieving image binary stored in a database.

Hi, i’m having problems retrieving my images. They’re in a mysql database, and i want to display them on my webpage. The problem is whenever i try to use a header to set the content type, i run into the “header already set” error. I just want to change the header for one line so i can display the image with an echo command, how do i do this?

You must send headers before any other output.

header() has to be the first thing that gets outputted to the browser.

u have output before u use the hader function.

make sure there is nothing (not even withspace) before ‘<?php’.

and move the header that far to the begining of ur script that there is no echo or print before the header function.

but i need other output before i add the image, am i still going to be able to output normal HTML stuff if i set the header to image earlier?

to clarify - what i need is a legal way to do

<?php echo('text content') header('Content-Type: image/jpeg'); echo($image_binary_variable) echo('more text content') ?>

You can use:

echo(‘text content’);
ob_clean();
header(‘Content-Type: image/jpeg’);
echo($image_binary_variable);
echo(‘more text content’);

u cant output both an image and html.

if u are using the same file u have to have an indicator whethere it is outputing the image or the html. then u can use an if to have no output if it is an image.

e.g.:
[php]<?php
if(!isset($_GET[‘img’])
{
echo(’…’);
}
else
{
header(‘Content-Type: image/jpeg’);
die($image_binary_variable);
}
echo(’…’);
?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service