store and display picturs from/into a blobfield

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dpichowiak
Forum Newbie
Posts: 1
Joined: Wed Nov 13, 2002 7:53 am

store and display picturs from/into a blobfield

Post by dpichowiak »

How can I display a gif or jpg picture, from a blob filed.
or display a stored pfd/doc document.
(MySQL and PHP 4.2)
thanks
Dieter
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

When you attempt to display the file you need to make sure that you give the page the correct MIME content type:
http://www.utoronto.ca/ian/books/html4e ... etype.html

To do this you would put something like this, if for example you wished to display a gif, at the top of the script:

Code: Select all

header('Content-type: image/gif');
Mac
Elena Mitovska
Forum Newbie
Posts: 6
Joined: Mon Nov 18, 2002 3:43 am
Location: Ukraine
Contact:

Post by Elena Mitovska »

For outputiing images from database Blob field I use folowing way:
first of all there are 2 php files:
index.php - that show image on page:

<img src='print_image.php?item_no=".$res[$i][0]."'>

This file calls other file 'print_image.php', that retrieves image from database:

$MainSQL="SELECT Photo FROM images where Item_no=".$item_no;
$res = $db->select($MainSQL);
$data = $res[0][0];
print $data;

so image is output in index.php file
Post Reply