views:

95

answers:

1

I'm solving problem of storing files in my web app.

I've already done some applications where files were stored in filesystem (simple upload of a file via PHP) and I wasn't sure how to solve the security issues correctly (I have the webapp on a shared webhosting). Is there any "manual" or book which target these issues in detail?

Recently, I've done an webapp where files are stored in MySQL database and it seems to be very easy for usage and I don't need to solve the permissions for the files. The disadvantage is that there's additional overhead of the system.

What is better according to you? (I have small files ~ 100kB)

Thank you!

+1  A: 

Each solution has its pros and cons.

Storing files in the DB is great for small files. Just remember to keep the files themselves and any metadata about those files in two different tables. This will prevent your queries from being slowed down by the binary data. Also keep in mind that, overtime, this can lead to very large DB tables.

File system storage is great, but keep in mind that you're going to have to keep file permissions / security in mind moreso than you would if you stored them in the DB.

I hope this steers you in the right direction. Post a comment if you have questions.

Levi Hackwith
Why should I keep file content and metadata in two tables? I thought the table is composed of columns and a blob column is just a "pointer" for mysql where data actually are - so I'm not sure why it should be slower. But thank you for the tip!I was thinking: The size of table with files may be splitted in a number of smaller tables (for example table_1, table_2, .. ) and thus preventing of a crash of one big table.
MartyIX
And all those pros and cons are covered in depth @ http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay
derobert
@MartyIX: It'll be slower if you use a stupid ORM that does `SELECT * …`.
derobert
The reason you want to keep the data in two tables is because if you do "select size from image_table" the db is still going to run through all the table columns including the field containing the binary data in order to compile your result set. By keeping the data separate, you keep the db from querying unnecessary data, thus increasing performance.
Levi Hackwith