Click to See Complete Forum and Search --> : displaying images stored in a mysql blob via php
cashton2k
05-20-2007, 04:44 PM
Hi, I have a database with images stored as blobs. I want to be able to download them and display them as a part of a webpage (in <img> tags).
by googlin it ive tried come up with the following but it doesnt worh
i have a file iconloader:
<?php
include "../../setup/dbconnect.php";
$result=mysql_query("SELECT Filetypeimg FROM filetypes WHERE FileTypeID='$filetypeid' ");
$image=mysql_fetch_object($result);
Header( "Content-type: image/jpeg");
echo $image;
?>
and then in the file i want to display, the image:
any ideas? thanks
cashton2k
05-20-2007, 05:20 PM
correction:
<?php
include "../../setup/dbconnect.php";
$filetypeid = $HTTP_GET_VARS['filetypeid'];
$result=mysql_query("SELECT Filetypeimg FROM filetypes WHERE FileTypeID='$filetypeid' ");
$image=mysql_fetch_object($result);
Header( "Content-type: image/jpeg");
echo $image;
?>
and
<img src="setup/imageloader.php?filetypeid=<?php echo $row2['FiletypeID']; ?>
(filetypeimg is the blob)
NogDog
05-20-2007, 09:00 PM
echo $image->Filetypeimg;
cashton2k
05-21-2007, 04:41 AM
still not workin, kinda hard to tell which part doesnt work, no errors etc.
bokeh
05-21-2007, 07:18 AM
<?php
# switch on error reporting
ini_set('display_errors', 'On');
error_reporting(E_ALL);
# use require, not include, for essential files.
# make certain this file produces no output (white space).
require("../../setup/dbconnect.php");
# use curly syntax around variables. Limit your query to one result.
$query = "SELECT Filetypeimg FROM filetypes WHERE FileTypeID='{$filetypeid} LIMIT 1'";
# add some error checking
$result = mysql_query($query) or die("Query failure<br>\n Query:- {$query} <br>\n Error:- ".mysql_error());
# add more error checking
if(mysql_num_rows($result))
{
$image = mysql_fetch_object($result);
header("Content-Type: image/jpeg");
die($image->Filetypeimg);
}
else
{
echo 'No image matches that ID';
}
?>
cashton2k
05-21-2007, 07:25 AM
ah cheers got it going great!
lol i didnt know what differance between require and include was
thanks again