Storing image pathes in a database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bagi
Forum Newbie
Posts: 24
Joined: Thu Oct 31, 2013 10:50 am

Storing image pathes in a database

Post by bagi »

Hi all,
I have an internet store and i need to store images of an item in db. I think that I need to store pathes, but not images (because there will be right load on db, i must to distribute it on db and fs). But how i can store that? I have a varuant with storing like "url;url", but it is a good way?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Storing image pathes in a database

Post by requinix »

If you have multiple servers then storing the images themselves in the database might be easier, otherwise you'd have to replicate the image files some other way (perhaps uploading them to an external source like Amazon S3).

Remember to never put multiple pieces of information into a column - no "url;url" but instead two rows each with one URL.

Storing them in the database: store the original filename (if you need it), size (is nice to have), type (JPEG, GIF, etc.), and raw data (in a BLOB or binary-type column)
Storing just the filenames: store the original filename (if you need it), the file path, and the size and type are optional (might be easier to get that information from the database than the files themselves)
bagi
Forum Newbie
Posts: 24
Joined: Thu Oct 31, 2013 10:50 am

Re: Storing image pathes in a database

Post by bagi »

Yes, you are right, butI dont understand about
Storing them in the database: store the original filename (if you need it), size (is nice to have), type (JPEG, GIF, etc.), and raw data (in a BLOB or binary-type column)
For what? Size column is needlessly, type i can get using regexp or db opportunities. And again: i don't need it. I will only output images on a page and small version of these images in search, only these purposes. Deleting, removing, editing of an image have to be easy
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Storing image pathes in a database

Post by requinix »

True, you don't need to store the image size since you have the image data itself. Personally I would rather have the value there than have to do a calculation every time.

You need the size so you can send a Content-Length header. It is optional but a very good thing to do.
Post Reply