Storing images as long blobs

This is a discussion on "Storing images as long blobs" within the PHP Forum section. This forum, and the thread "Storing images as long blobs are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jul 1st, 2006, 14:05
Junior Member
Join Date: Feb 2006
Age: 25
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Storing images as long blobs

Hi there I am storing images in my db as long blobs and have successfully managed to display them for each record using this bit of code...

<img src="GetImage.php?ID=<?php echo $row_Recordset1['ID']; ?>"

which creates a separate request from the GetImage.php page for each record in db...

Trouble is I would like to display a default image if there is no image in the db for that record...

I realise this must be done in the GetImage.php page but I am not sure what to check for or what value to send as my default image since the blob is binary?

Here is my code for GetImage.php...


if($_GET['ID'])
{
mysql_select_db($database_The_DB, $The_DB);
$query_Recordset1 = sprintf("SELECT ID, Picture, ImageType FROM User_Details WHERE ID = '%s'",$_GET["ID"]);

$Recordset1 = mysql_query($query_Recordset1, $The_DB) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
//echo $query_Recordset1, $totalRows_Recordset1;
$data = mysql_result($Recordset1,0,"Picture");
$type = mysql_result($Recordset1,0,"ImageType");

//if ($data = "")
//$data = /Images/Home_Graphic.jpg
//$type = image/jpg

header("Content-type: $type");
echo $data;
}
?>

i would really appreciate any help on this.

Thanks in advance

Brian
Reply With Quote

  #2 (permalink)  
Old Jul 1st, 2006, 21:23
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Storing images as long blobs

I don't have a lot of time, but my first thought is that this should be fairly easy, like

Code: Select all
 if($rows_Recordset1['Picture']) { //$data=whatever } else { //$data=default}
Not a php expert, hope this isn't all wrong.
Reply With Quote
  #3 (permalink)  
Old Jul 1st, 2006, 21:57
Junior Member
Join Date: Feb 2006
Age: 25
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Storing images as long blobs

Thanks so much for your reply masonbarge...

I beleive that to be the correct way to do it but the trouble is I don't know what to assign to data because it is stored as a Long Blob in the database...

should it be something like default.jpg or should it be a binary number...

I am very confuesd about this little detail and would be very grateful if anyone could help me undertsand this.

Thanks again
Reply With Quote
  #4 (permalink)  
Old Jul 2nd, 2006, 18:44
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Storing images as long blobs

If the default image is in the database too - say at id "zzz" - why not change your select to read

select ..... where ID = "wanted" or ID = "zzz" order by ID desc ....

then you don't have to bother checking ... if the record you want exists, you get it back as the first record; if not, you get the default back as the first and only record.
Reply With Quote
  #5 (permalink)  
Old Jul 3rd, 2006, 19:19
Junior Member
Join Date: Feb 2006
Age: 25
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Storing images as long blobs

Genius! Worked a treat thanks a lot

Brian
Reply With Quote
Reply

Tags
storing, images, long, blobs

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Matching HTML And Storing josephman1988 Other Programming Languages 0 Feb 18th, 2008 13:25
How long? dhall Webforumz Cafe 23 Aug 29th, 2007 01:15
storing lists of friends keyboardcowboy Website Planning 0 May 22nd, 2007 19:14
What took me so long? Napalm Introduce Yourself 3 Jan 6th, 2005 14:43
Storing and Retrieving Multiple Objects From 1 ... courtjester Classic ASP 9 Sep 12th, 2004 16:37


All times are GMT. The time now is 08:34.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43