I am writing a php application and wondered whether it's an awful idea to keep complete files within the database. Files ought to be around 100-200kb mostly text files (txt, doc, docx and so forth) or small image files. Or perhaps is it simply an ordinary wrong idea?

It truly is dependent around the situation?

  • The way the files likely to be distributed?
  • Would be the files used stand alone or could they be a part of an system that might have its very own authorization and authentication logic?
  • What is your backup strategy?
  • Do you want replication?
  • Must you support a large amount of I/O?
  • How about caching?

With that said, I'd lean toward some type of filesystem for documents on the database.

Advantages:

  1. You don't need to be worried about write permissions around the file store.
  2. You don't need to try to synchronise files on filestore with rows within the database, staying away from orphaned files or damaged links. For example, you are able to automically cascade remove files when related submissions are erased.
  3. In a few databases (for example Oracle and SQL Server) you are able to index files and check within them using SQL
  4. You don't need to be worried about unique filenames, folders and it could make uploading simpler in some instances
  5. Simpler to safeguard use of files so only authorised customers can easily see them

Disadvantages:

  1. Performance of serving files frequently suffers in comparison to filestore
  2. Can result in large databases. Care must be taken when choosing binary posts.
  3. More try to connect to files and serve the contents - you'll need specialized handlers etc.

Personally, I like the thought, particularly if the DB stores them compressed or else you compress them by hand.

Amongst other things, this means you don't have to be worried about unique names for files, which saves lots of complexity.

Professional: highly portable.

Disadvantage: you cannot so something with it using SQL (indexing, searching, etc) and you will need to add metadata in other posts (content type, filename, etc) to enhance (re)usability and maintainability.

I would not do this. The disk file system is way better suited system for individuals tasks.