Web Development – Store Images in Database or Files with Database Link?

databaseMySQLPHPweb-development

Is it appropriate to store the image files in the database? Or it would be better to store only the path of the file in the database, while keeping the file itself on the server?

Are there any other methods for doing this right?

Best Answer

I strongly advise you to store the images in the filesystem and not in the database.

Storing images in the database has several disadvantages:

  • The database might grow unexpectedly large. Sometimes space is an issue. For example with SQLServer express you have a 4GB limit.

  • Data migrations can become a pain, for example if you switch from SQLServer to Oracle

  • Queries can become very slow and you'll have a high database load

  • Interoperability with other applications is better if the images are on the filesystem and other applications use a different database. You can also access them directly and do not need database tools.

  • Worse performance in general

  • You'll probably have to create temporary files when retrieving the images from the database anyway. That's unnecessary.

These disadvantages far outweigh the cost of keeping the paths to the images stored in the database synchronized with the filesystem. There're only few special cases in which it's better to store the images in the database.

Related Topic