Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010

    Unanswered: Should I store images in the db or in a folder?

    Hi all,
    While browsing some php code yesterday I found out that it was possible to store images in a database in the form of 'blobs'.

    I currently have a website that allows members to upload a profile picture of themselves. The pictures are renamed with a time/date hash and the link to the users picture is stored in the database. The actual thumbnail itself is stored as a jpg in a folder.

    My question is this...
    From a scaleability point of view, is this the right way to be doing this? I currently have around 1500 members with about 50 new ones joining every day. The site is really beginning to take off and I'm wondering whether a better way would be to store the pictures themselves in the database?

    What are the pro's and con's of this??

    I notice in myPhpAdmin that it will only allow me to export/import a max of 50Mb so I'm thinking that this would be used up a lot quicker if I store images in the database.

    However, I'm also unsure of how many images I can hold in the folder and what effect, say, 50,000 or 500,000 images would have in one folder??

    Can anyone give me any advice on the best solution for this?

    I wondered how facebook do it as they have obviously got millions of user profile pictures to deal with....??

    Many thanks for any help you can give me



  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    it's a pretty safe bet that facebook does not store images in a database

    nor should you

    as for pros/cons, the only pro is that your images are backed up automatically along with your database -- but then, taking a database backup will be slower

    one thing's for certain, if you're thinking about scalability, you'll want to develop some better tools thatn phpmyadmin | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2003
    Provided Answers: 23
    A couple of years ago someone actually did some research whether to store images (blobs) in the database or not and the outcome was quite interesting I think.

    The bottom line of that research:
    Quote Originally Posted by Russell Sears, Catharine Van Ingen, and Jim Gray
    The study indicates that if objects are larger than one megabyte on average, NTFS has a clear advantage over SQL Server. If the objects are under 256 kilobytes, the database has a clear advantage.
    I have no idea to which extend this can be "transferred" to other databases. But I think the general conclusion is probably similar with other DBMS. The size of the blobs will most definitely change when using a different DBMS and/or filesystem

    Here is the link:
    To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem - Microsoft Research

  4. #4
    Join Date
    Jul 2010
    Some great replies there. Thanks to r937 and shammat.

    I think I'll just stick with the method I use now. The images are only around 10K so they could go in a database but for the extra hassle and the negligible benefits I think the system I have at the moment is fine.

    Thanks again for your wise words and input. It is very much appreciated.



Posting Permissions

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