Forum Moderators: coopster

Message Too Old, No Replies

How to store Pictures in Mysql

How to store Pictures in Mysql

         

Butterfly Wing

4:41 pm on Oct 23, 2004 (gmt 0)

10+ Year Member



Folks ,

How do i store pictures in the Mysql database , am very new to this mysql , plz gibve me step by step if u can. i will really appreciate u ..

thanks

StupidScript

5:37 pm on Oct 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to the forums, Butterfly_Wing!

I just asked a similar question, and received an answer, in this thread [webmasterworld.com].

Basically upload the file, and use the LOAD_FILE() MySQL function to dump into your table's blob type field. Getting it out in picture form requires your PHP to be configured with the "GD" libraries, and various other image-related things. Find out all about it, here. [boutell.com]

Enjoy the forums! :)

Butterfly Wing

10:37 am on Oct 24, 2004 (gmt 0)

10+ Year Member



Hellow "Stupid Script",

Thanks for tips but.... am so new to all this kind of thing , so can u tell plz , at the moment all i wanted to know is just to make a "Mysql database" that stores "Picutre" & "Description" on two tables i need, right now i dont need php form, just to store pic and the description..

\\Pic\\Description\\
\ \\ \\
\\ \\ \\

ergophobe

3:19 pm on Oct 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't store pics in MySQL databases, since I find that generally I want access to the file for use with editing software and so on and if you know the address, it's way faster to just pull it from the filesystem rather than the DB. So what I do is something like this

table pictures
picture_id int(10) - primary key
file_path char(255)
description char(255)

Then I use that information to find the file on the filesystem.

Butterfly Wing

4:15 pm on Oct 24, 2004 (gmt 0)

10+ Year Member



Thanks Ergo,

Can u be more specifics onb the cooding plz,

thanks a lot

[edited by: jatar_k at 5:45 pm (utc) on Oct. 24, 2004]
[edit reason] removed email [/edit]

StupidScript

5:15 pm on Oct 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's my test database for storing images (sorry for the column line-up!):
mysql> use test;

Database changed

mysql> describe blobber;

+--------+---------+------+-----+---------+----------------+

¦ Field ¦ Type ¦ Null ¦ Key ¦ Default ¦ Extra   ¦

+--------+---------+------+-----+---------+----------------+

¦ id  ¦ int(11) ¦  ¦ PRI ¦ NULL ¦ auto_increment ¦

¦ picbox ¦ blob ¦ YES ¦  ¦ NULL ¦     ¦

¦ info ¦ text ¦ YES ¦  ¦ NULL ¦     ¦

+--------+---------+------+-----+---------+----------------+

3 rows in set (0.00 sec)

You can store pictures in one of two ways: as a path to the file, as suggested, or as a text string in a text or blob MySQL field.

In my test table, I store the string version of the picture in the "picbox" field, and the path to the actual image file in the "info" field.

Here's a small piece of what it looks like in the database:

select * from blobber limit 1;

+----+------------------+-------------+

¦ id ¦ picbox   ¦ info  ¦

+----+------------------+-------------+

¦ 1 ¦ Gif89ai?D?x^.etc.¦ /image.gif ¦

+----+------------------+-------------+

There can be a lot of data in "picbox", depending on how big the picture file is.

I use PHP to send the instructions to "LOAD_FILE('/image.gif')" to put the picture data into "picbox", but you can do it from a terminal or (probably) using one of the graphical MySQL managers.

Try just storing and using the path to the image file while you learn, Butterfly_Wing. If you use the "picbox" method of storing the picture file data, you need to do a bunch of other stuff to your PHP installation to get it to work.

Butterfly Wing

9:40 am on Oct 26, 2004 (gmt 0)

10+ Year Member



Thanks a lot to ya all, let me try it ...i couldnt i will get back to ya all

thanks a lot for ur time and eefort