Connecting Tech Pros Worldwide Help | Site Map

how to get a blob image out of a record?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 04:18 AM
sams
Guest
 
Posts: n/a
Default how to get a blob image out of a record?

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

  #2  
Old July 17th, 2005, 04:18 AM
Andy Hassall
Guest
 
Posts: n/a
Default 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>
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.