Connecting Tech Pros Worldwide Forums | Help | Site Map

how to get a blob image out of a record?

sams
Guest
 
Posts: n/a
#1: Jul 17 '05
Iam posting this after trying many tutorials in the NG and failing to
retrieve the blob out of a record. So please bear with me before
before you pull the water hose or flame throwers ......

I can upload a Jpeg image file perfectly. Iam using this snippet to do
that..

<!-- addpic.php snippet !-->
....
$file = fopen($_FILES['pict']['tmp_name'], "rb");
$pic = fread($file, 5000000);
// mysql_query(INSERT .... code goes here

MySQL Admin shows that the picture I have uploaded 430KB as 428KB, not
sure this matters. Now I want to get the image displayed inside my
html page

<!-- html code goes here ---->
<img src="getimg.php?i=8" height=244>

<!-- here is the code snippet for getimg.php to extract the blob
file -->
($row = mysql_fetch_array($result))
$data = $_GET[$row['pic']];
header("Content-type: image/jpeg");
include $data;
// echo $data;


Iam only getting a broken image nothing else. What am I doing wrong?

Appreciate anyone help.

Sam

Andy Hassall
Guest
 
Posts: n/a
#2: Jul 17 '05

re: how to get a blob image out of a record?


On 19 Mar 2004 11:14:58 -0800, sams@freeddns.org (sams) wrote:
[color=blue]
>Iam posting this after trying many tutorials in the NG and failing to
>retrieve the blob out of a record. So please bear with me before
>before you pull the water hose or flame throwers ......
>
>I can upload a Jpeg image file perfectly. Iam using this snippet to do
>that..
>
> <!-- addpic.php snippet !-->
> ....
> $file = fopen($_FILES['pict']['tmp_name'], "rb");
> $pic = fread($file, 5000000);
> // mysql_query(INSERT .... code goes here[/color]

You've snipped the most likely place for a mistake here. How exactly did you
pass the data into the statement? You have to careful since it's binary data.
Did you apply mysql_escape_string()?
[color=blue]
>MySQL Admin shows that the picture I have uploaded 430KB as 428KB, not
>sure this matters.[/color]

This may well be due to mangling resulting from not escaping the data
properly.
[color=blue]
> Now I want to get the image displayed inside my
>html page
>
> <!-- html code goes here ---->
> <img src="getimg.php?i=8" height=244>
>
> <!-- here is the code snippet for getimg.php to extract the blob
>file -->
> ($row = mysql_fetch_array($result))
> $data = $_GET[$row['pic']];[/color]

What's $_GET doing here?
[color=blue]
> header("Content-type: image/jpeg");
> include $data;[/color]

include?
[color=blue]
> // echo $data;[/color]

That's better.
[color=blue]
>Iam only getting a broken image nothing else. What am I doing wrong?[/color]

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Closed Thread