Page 1 of 1

Re: Storing then displaying image from database

Posted: Mon Mar 26, 2012 10:17 am
by freshnet
You need to have your header as header("Content-type: image/jpg"); Is that what you're getting from your code?

Re: Storing then displaying image from database

Posted: Tue Mar 27, 2012 2:44 am
by freshnet
This won't work if you've printed/echoed anything to your page before the header, have you done that? How about if you have just the header and the variable on a page and call that page from your first page, e.g.

Code: Select all

//page 1
$result=mysql_query("SELECT * FROM LetterImages WHERE LetterID=1 AND Page=1");

//fetch data from database
$sqldata=mysql_fetch_array($result);

$encoded=stripslashes($sqldata['Data']);
$ftype=$sqldata['Type'];
require 'page2.php';

//page 2
//tell the browser what type of image to display
header("Content-type: $ftype");
//decode and echo the image data
print $encoded;

Re: Storing then displaying image from database

Posted: Tue Mar 27, 2012 3:45 pm
by freshnet
that's generally what people advise unless you have to use blobs!