Jump to content

Pictures In Database

How can i do it?

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Pictures In Database How can i do it? Rate Topic: -----

#1 User is offline   Man2u2uk 

  • W.R. Lieutenant
  • Group: Members
  • Posts: 396
  • Joined: 14-April 07
  • Gender:Male

Posted 19 April 2007 - 03:16 AM

Hi,


how would i go about storing pictures in a database & then echoing them
0

#2 User is offline   Ben Abrams 

  • The buddy system:never fails
  • Group: Administrators
  • Posts: 1,850
  • Joined: 04-April 06
  • Gender:Male

Posted 19 April 2007 - 04:51 AM

View PostMan2u2uk, on Apr 19 2007, 09:16 AM, said:

Hi,
how would i go about storing pictures in a database & then echoing them


you would be taking advantage of the the BLOB fields in databases.

However, this is NOT a good idea to do with images any bigger then thumbnails. As your putting a lot of stress on the mysql server if you do, which some hosts do not allow. I really reccomend uploading the file and then saving the path to the file in the database instead.

however, i will answer your question breifly..

$image = addslashes(@fread(@fopen($dir.'/'.$file, "r"), @filesize($dir.'/'.$file))))

Then $image is ready for an INSERT statement..
to retrieve, something like this, after a SELECT query.
$image = $r['myimage']; 
header("Content-type: image/gif"); 
print $image;


Agin i need to WARN you from doing this. its really not the best option.
EDIT

Read this: http://www.webmaster...orum88/9091.htm

View PostSirkent, on 21 September 2007 - 04:26 AM, said:

<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
0

#3 User is offline   Man2u2uk 

  • W.R. Lieutenant
  • Group: Members
  • Posts: 396
  • Joined: 14-April 07
  • Gender:Male

Posted 19 April 2007 - 05:02 AM

Thanks,

all i need to do is echo pictures from my databse on a catalog page. (its only for university work)

the pictures only really need to be thumbnail size anyway
0

#4 User is offline   benbacardi 

  • Administrator
  • Group: Administrators
  • Posts: 1,140
  • Joined: 06-April 06
  • Gender:Male
  • Location:United Kingdom

Posted 19 April 2007 - 08:12 AM

Hey,

Is this for the Web Project or Intro to Internet Apps one - because for the Web Project, I've got a similar thing for products.

In the database each product has an ID, and I just use that ID as the name (or part of) of the product image.

For example, one product could be ID number 48, and the image is in the folder images/products/48.jpg

Then I use PHP to build up the image string using to ID where needed.

Make sense?
0

#5 User is offline   Man2u2uk 

  • W.R. Lieutenant
  • Group: Members
  • Posts: 396
  • Joined: 14-April 07
  • Gender:Male

Posted 19 April 2007 - 08:54 AM

Thanks ben,

i managed to do it by storeing the images URL in the database: i.e http://www.google.com/images/bike.jpg

then searching for it: $prod_pic=mysql_result($result,$i,"prod_pic");

then echoing it: <? echo "<img src=\"$prod_pic\" />"; ?>
0

#6 User is offline   benbacardi 

  • Administrator
  • Group: Administrators
  • Posts: 1,140
  • Joined: 06-April 06
  • Gender:Male
  • Location:United Kingdom

Posted 19 April 2007 - 09:14 AM

Effectively the same idea then :)
0

#7 User is offline   Ben Abrams 

  • The buddy system:never fails
  • Group: Administrators
  • Posts: 1,850
  • Joined: 04-April 06
  • Gender:Male

Posted 19 April 2007 - 09:36 AM

Glad you didnt use Binary file in mysql :D

View PostSirkent, on 21 September 2007 - 04:26 AM, said:

<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
0

#8 User is offline   EncoderDecoder 

  • W.R. Sergeant
  • Group: Members
  • Posts: 260
  • Joined: 01-March 11
  • Gender:Female
  • Location:Philippines

Posted 17 May 2011 - 07:56 AM

View PostMan2u2uk, on 19 April 2007 - 08:54 AM, said:

Thanks ben,

i managed to do it by storeing the images URL in the database: i.e http://www.google.com/images/bike.jpg

then searching for it: $prod_pic=mysql_result($result,$i,"prod_pic");

then echoing it: <? echo "<img src=\"$prod_pic\" />"; ?>



we had the same idea.. ^_^
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users