Storing images in mySQL or folders (hard drive)

Inquiring if it is better to store images in folders or database

Page 1 of 1

3 Replies - 2639 Views - Last Post: 11 September 2009 - 08:47 AM Rate Topic: -----

#1 xpeditor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-April 09

Storing images in mySQL or folders (hard drive)

Posted 08 September 2009 - 06:26 PM

Hey Guys,

I'm just about to start a project with a company and I'm a little rusty. I'm looking for a nudge in the right direction. Essentially, the company is looking to build and maintain a database of images. They would like a user to be able to upload a picture and tag it (add a caption to it). Also, they would would like to be able to query the database and generate some html to display a picture that a user may have searched for. This is going to be web based and we will be using php and mysql.

My question is: do you guys think it would be more efficient to store the images in the database along with all the relevant information?

or

do you think its best to store the images in separate folders based on maybe the user (not the issue...that can be sorted out later) and subsequently store all related data, including the location of each image in the database?
For example, store the image in "/xpeditor/images/random image name" and the particular record for this image in the image table can be "id--user--location--caption".

I'm thinking the latter may be easier on space and resources because I know that storing images in a database uses a significant amount of space.


Please advise...and thanks in advance guys

Is This A Good Question/Topic? 0
  • +

Replies To: Storing images in mySQL or folders (hard drive)

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Storing images in mySQL or folders (hard drive)

Posted 08 September 2009 - 06:33 PM

Don't store images in a database. Just don't do it. Store them in the filesystem, with a link in the database to its location in the filesystem.
Was This Post Helpful? 0
  • +
  • -

#3 mazeroth  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 11-December 08

Re: Storing images in mySQL or folders (hard drive)

Posted 11 September 2009 - 06:41 AM

View PostJackOfAllTrades, on 8 Sep, 2009 - 05:33 PM, said:

Don't store images in a database. Just don't do it. Store them in the filesystem, with a link in the database to its location in the filesystem.


Agreed. You are just causing more overhead for the database by storing the files in there. Remember, it's faster to read from the file system than to read from the database server as well. You can cache but then doesn't that just defeat the whole purpose anyways?
Was This Post Helpful? 0
  • +
  • -

#4 d.buckner  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 04-December 08

Re: Storing images in mySQL or folders (hard drive)

Posted 11 September 2009 - 08:47 AM

I am also working on a similar site, it is much better to store the images in a folder and reference the filename in the database. It is possible to store the image itself in the database but not recommended. The table in the database was set up like this:

id {I used this as an auto incrementing primary key for future use if necessary}
date {this is a datetime to show when the image was uploaded}
photo {this field stores the name of the image (ie. photo001.jpg)}
title {The title or caption of the image}
description {Description of the contents of the photo.}

I created this table so when there are updates/new photos, I don't have to re-write the page to change the images. This is working great to display the images.

Hopefully this helps...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1