Storing then displaying image from database

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 359
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Mon Mar 26, 2012 10:17 am

You need to have your header as header("Content-type: image/jpg"); Is that what you're getting from your code?

User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 359
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Tue Mar 27, 2012 2:44 am

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;

User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 359
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Tue Mar 27, 2012 3:45 pm

that's generally what people advise unless you have to use blobs!

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest