Storing files in database Vs file system

2019-01-01 02:23发布

问题:

one of my customer ask for a Document Management System for some thousands of document in different format i.e. pdf, doc, docx etc. My question is what is the best way to store this file in database or in file system? How easy to secure a document between the two approach?.

Fast retrieval of the files is the key requirement..

am using mysql if that helps

Regards.

回答1:

You might want to store it directly into filesystem.

When using filesystem careful with :

  • Confidentiality : Put documents outside of your Apache Document Root. Then a PHP Controller of yours will output documents.
  • Sharded path : do not store thousands of documents in the same directory, make differents directories. You can shard with a Hash on the Filename for example. Such as /documents/A/F/B/AFB43677267ABCEF5786692/myfile.pdf.
  • Inode number : You can run out of inodes if you store a lot of small files (might not be your case if storing mostly PDF and office documents).

If you need to search for these documents (date/title/etc...) you may want to store metadata into a database for better performances.

FYI, in this question MS SQL Server has FILESYSTEM column type (like an hybrid), but at the moment MySQL doesn\'t have an alternative.



回答2:

Using filesystem access for big datablobs means in general faster access and less overhead than storing them in a mysql database.

One interesting and possibly related post: Storing Images in DB - Yea or Nay?



回答3:

for high performance you should use File system, using php glob function and JS interface. I finished project like this in march.