Forum Moderators: coopster

Message Too Old, No Replies

getting image(BLOB) to display on website

         

welshbryant

9:18 pm on Mar 6, 2007 (gmt 0)

10+ Year Member



Hey guys, it seems many people here are very knowledgable hence why i am posting here in regards to taking a blob (image) that was stored on my mysql server (not by choice as it's required to be on the server itself and not a directory). I have recently had problems trying to access the blob and display it as an html image. The method i used is two php pages which are below

testbrowse.php

<?php
header("content-type: image/jpg") ;
include("connect.php");

$query = "SELECT uploaded_photo FROM photo";
$results = mysql_query($query) or die(mysql_error()) ;

echo $row['uploaded_photo'] ;


?>

and the page that calls this page image.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title>Sans Titre</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="HAPedit 3.1">
</head>
<body bgcolor="#FFFFFF">

<img src = "testbrowse.php" />
</body>

</html>

it simply comes up as the broken picture (box with red x inside) and was hoping someone might catch one of the mistakes i made.

Uploaded_photo is the column field which holds the blob and photo is the table name that contains name, type, photo blob, photo id. I simply just want it to output the picture of the first blob. Thanks in advance for any help.

sned

9:50 pm on Mar 6, 2007 (gmt 0)

10+ Year Member



I don't know if it was a typo or not:

<?php
header("content-type: image/jpg") ;
include("connect.php");

$query = "SELECT uploaded_photo FROM photo";
$results = mysql_query($query) or die(mysql_error()) ;

// need to fetch the array to get this line to work:
$row = mysql_fetch_assoc($results);

echo $row['uploaded_photo'] ;

?>

-sned

welshbryant

10:01 pm on Mar 6, 2007 (gmt 0)

10+ Year Member



Thank you Sned for the quick reply. I editied the code as you suggested and when i treid to load image.php, it still was the broken images. When i looked at the testbrowse.php, it showed the binary and ascii code for the image.

The link to see what the page produces is :

<snip>

[edited by: eelixduppy at 10:03 pm (utc) on Mar. 6, 2007]
[edit reason] no URLS, please-See Terms of Service [/edit]

sned

12:31 am on Mar 7, 2007 (gmt 0)

10+ Year Member



ah yes, forgot about that part, you'll probably need imagejpeg [us2.php.net]:

imagejpeg($row['uploaded_photo']);

-sned

welshbryant

1:02 am on Mar 7, 2007 (gmt 0)

10+ Year Member



Sned,

i tried adding that code however upon reading the documentation i found it has to take a value from a image create function. I created the code below with that in mind. When i load the page on my web server and try to access it, it says

Warning: Cannot modify header information - headers already sent by (output started at /home/welsh/public_html/testbrowse.php:14) in /home/welsh/public_html/testbrowse.php on line 17

then the ascii and binary code below that.

my new code is below:

<?php

header("content-type: image/jpg") ;
include("connect.php");

$query = "SELECT uploaded_photo FROM photo";
$results = mysql_query($query) or die(mysql_error()) ;

// need to fetch the array to get this line to work:
$row = mysql_fetch_assoc($results);
$news = ImageCreateFromString($row['uploaded_photo']) ;
$final = imagejpeg($news);
echo $final;

?>

Any Suggestions? I appreciate all your help, this has just been so frustrating for me and it's nice to know there is help out there.

welshbryant

2:19 am on Mar 7, 2007 (gmt 0)

10+ Year Member



sned,

I got the header error to go away however it is still showing as a broken link picture. my code is below:

<?
include("imgheader.php") ;
?>

<html>

<head>
<title>Sans Titre</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="HAPedit 3.1">

</head>
<body bgcolor="#FFFFFF">


<?php

include("connect.php");

$query = "SELECT uploaded_photo FROM photo";
$results = mysql_query($query) or die(mysql_error()) ;

// need to fetch the array to get this line to work:
$row = mysql_fetch_assoc($results);
$news = ImageCreateFromString($row['uploaded_photo']) ;
$final = imagejpeg($news);
echo $final;

?>