SitePoint Sponsor

User Tag List

View Poll Results: Store images as files or actually in the database?

8. You may not vote on this poll
  • Images as organised files referenced by database

    8 100.00%
  • Images stored in database blobs

    0 0%
Results 1 to 2 of 2
  1. #1
    SitePoint Zealot secoif's Avatar
    Join Date
    Jul 2006
    Brisbane, Australia
    0 Post(s)
    0 Thread(s)

    Images stored as files or as database blobs?

    Posted this in general php help but figured it was more suited here.

    I'm creating a custom gallery (PHP/MYSQL) for my client to upload his artwork to.

    I'm not sure what is a better system to use:
    Storing the images as files in some kind of organised directory structure and store links to the images in the database, or actually store the images in the database.

    What are the advantages/disadvantages of both methods in regard to performance, simplicy and functionality.

    I did some brief googling found a similar query but I'd like a second opinon...

    What does the sitepoint community have to say about it?

    store image files in MySQL or flat file

    I want to compare 2 image storage systems, one in MySQL and one in a flat file format:-

    1) performance

    As I read some articles / forums that someone says if the image stored in MySQL to be retreive more faster than stored in a flat file and someone have different ideas.

    2) backup

    Someone said it is easiler to backup the image files stored in a flat file than stored in MySQL database.

    3) security

    I would like to hear more about the 3 points that I pointed out since I will install the shopping cart in my website. Once I select the image storage method, then I cannot return it back.

    Pleaes give advise.

    Thanks a lot.


    Andy Ng

    From: ang@... Date: 04/18/2005 Status: Answered Points: 150
    Networking / LAN Administration
    No location specified
    Member since: February 2002
    View complete profile View all posts Send private message

    Answer 1

    1) the db performance takes a hit when you store the images in it.
    they increase th size for no gain.
    just store the path to the images.

    2) to backup the db, you need to be able to pull a copy of the sql file or else, dump contents to a file with full inserts.
    if you do not have that access then you can't backup anything in the db.
    ( unlikley, hosting companies do give that access )

    3) images will be copied of people want them. there is no 100% effective means to stop it.
    there is no risk to site security by having images in the site space instead of the db, the space should not be world writable anyways.

    Thanks in advance!

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2006
    0 Post(s)
    0 Thread(s)
    Store the images in an organized directory structure and store path info in the database. That way definitely works fine. Storing them as blobs might slow down the database and is unnecessary.
    I'm available for hire! -


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts