php:Store image into Mysql blob, Good or bad?

I have often built systems to store images in the database, there are pros and cons to doing this.

Pros:

  • All your data is kept in one place, if you migrate your website/database the images will just be there
  • Its easier to sort/delete/etc…
  • Since you have to serve it via a PHP script, you can perform additional things such as security if required, or image processing (obviously you can do this with flat file too, but you have to make sure the security cant be bypassed by leaving the images in a public directory).

Cons:

  • Its slower then serving a flat file from the webserver as a PHP script needs to retrieve it, and MySQL needs to return the data.
  • Your database will become large very fast and not all web hosts take too kindly to this.
  • The file system is faster for flat file storage and retrieval as thats exactly what a file system is designed for.

Leave a Comment