Hi everyone

I am having a problem with displaying an image from mysql with base64_decode.

my image viewer looks like this:

<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/site/dbconnect.php');

$result=mysql_query("SELECT * FROM images WHERE p_id='".$_GET['p_id']."'");

$table_returns=mysql_fetch_array($result);
$encoded=$table_returns['data'];
$image_name=$table_returns['image_name'];
$the_date=$table_returns['date'];


mysql_close($connect);

echo base64_decode($encoded);
echo $image_name;
echo $the_date;

?>

I don't know what I am doing wrong. When I pass an id through the url I always get this back:

IHDR``múào pHYsšœ MiCCPPhotoshop ICC profilexÚSwX“÷>ß÷eVBØð±—l"#¬ÈY¢’a„@Å…ˆ VœHUÄ‚Õ Hˆâ (¸gAŠˆZ‹U\8îܧµ}zïííû×û¼çœçüÎyÏ€&‘æ¢j9R…<:ØOHÄɽ€Hà

This is the part of my upload script that codes it:

//record the image contents into a variable
$contents1 = fread($fp1, filesize($filename1));

//close the file
fclose($fp1);

//encode the image into text
$encoded = chunk_split(base64_encode($contents1));

edit: i should probably mention that $the_date and $image_name both work fine

It looks like your sending the wrong header in your output script. Change the header type in your output by putting

header("Content-type: image/png");

in the top of your script.

when i try to apply a header it comes up with an error saying header has already been set

Warning: Cannot modify header information - headers already sent by (output started

oh god nvm i just got it working thanks so much for your help

when i try to apply a header it comes up with an error saying header has already been set

Warning: Cannot modify header information - headers already sent by (output started

Be sure you do not have any white space or blank lines in your script before the

<?php
header("Content-type: image/png");

oh god nvm i just got it working thanks so much for your help

Your welcome good luck, please mark this thread as solved.

This article has been dead for over six months. Start a new discussion instead.