Forums

This topic is locked

Up load images to my database

Posted 06 Mar 2007 01:12:27
1
has voted
06 Mar 2007 01:12:27 Damian Wright posted:
Hi I’m pretty new to coding, I’m using dreamweaver 8 and php and mysql,
Hi all
Been reading the forums help me out a lot thanks.

What I’m trying to do is upload images to my database them display them on another page.

I'm not to sure how i should format my database to accept images, I've read somewhere I should be using longblob for type in the database Field.

So far I can upload all the data and look like the image gets uploaded too, but it is not getting saved in the database so it will not display.

My database consist of 4 fields

Product ID, Product name, Description and Image
My image field is setup as below but I’m having no joy

Type= longblob,
Collation,
Attributes=BINARY
Null=Yes
Default,
Extra
Action

Rest of the database can be found here
www.overclock247.com/day187/db.JPG

Thanks in advance

Replies

Replied 06 Mar 2007 19:22:23
06 Mar 2007 19:22:23 Alan C replied:
HI Damian,

I've just been doing something similar - uploading images for display, it was not as easy as I expected. I evaluated all sorts of scripts to handle the uploading, but being a skinflint didn't want to pay for one, so I ended up writing my own very simple uploader. It works fine.

I also looked at whether it's better to put the images into a table and serve them from there, or put the images into a directory and the path in the database table. After looking around and reading a lot I decided to go with the latter - so what I now do is upload the image, look at it's properties, scale it to the size I want and form a thumbnail, also some checks in case the user sends an image that's too small even for a thumbnail, or big enough for thumbnail, but not big enough for full image, then I also strip out any odd characters from the filename, check its length, then store just the filename in the database because the path is constant.

I decided to go that way so that the images get served directly from the filesystem rather than having to come through mysql.

I'm sure others will disagree - but I've found that works for me <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

blob is the right field type or long blob depending how big your images might be - check out the mysql documentation for the exact details - but first check which version of mysql that your server is running just in case they are different

Reply to this topic