views:

104

answers:

5

I want users to be able to upload their CV in PDF, .txt, .doc, .docx; and allow potential employers to download the file.

What data type should I use? In MS MSQL, I would use varbinary(max), right? But since I'm new to MySQL I'm a bit confused. :)

+5  A: 

You have to use the BLOB type

Svetlozar Angelov
God, I love these FOSS variable names. PHP has a method called Explode() - I lol'd in class. :P And now MySQL has BLOB. Who comes up with this stuff?
Serg
Files shouldn't be stored on the database itself -- best method would be to to hold a path to the stored file on the server.
henasraf
@Sergio - It stands for Binary Large OBject
Peter Di Cecco
BLOB is a standard data type found in most database systems. http://en.wikipedia.org/wiki/Binary_large_object
iKnowKungFoo
+1 to counteract the -1, because this is actually the correct answer to the question, whether it's recommended or not.
Tatu Ulmanen
Binary Large OBject - other (non-free) DBMSs have them as well =).... My guess? Definitely a backronym.
Matt Luongo
@Sergio: if a `B` inary `L` arge `OB` ject complies with principles of `a` tomicity, `c` onsistency, `i` solation and `d` urability, it is called `ACID BLOB`. Welcome to the database world :)
Quassnoi
Also, just because storing files to disk is preferred, sometimes there's no other choice but to store a file in the database. And if you need to store a file in the database, you'd better know what data type to us. No reason to flag the answer down, it's correct per the original question.
iKnowKungFoo
I wouldn't see a reason to store in the database -- especially since large database sizes will eventually take more time to process and optimize. Though, I see your point and agree with it, I shouldn't have flagged it down. But, I can't revert back now unless he edits the answer.
henasraf
+3  A: 

You should use varchar holding a path to the file. File itself should not be stored in database.

Sam Dark
+1, plausible, in case of small images (such as avatars etc) the data could be reasonable to store in a DB, but when handling larger documents in formats like PDF, there's no sense.
Tatu Ulmanen
Would have the path allow users to download the file?
Serg
@Sergio, yes, if you programmed the PHP that way else no.
Don
A: 

Its usually a bad idea to store binary documents like DOC in MySQL. I would just upload them to the filesystem or convert to plaintext before saving to MySQL as BLOB or varchar.

Andrew Kolesnikov
If you'd store plain text, you'd ought to use the `TEXT` datatype.
Tatu Ulmanen
A: 

I agree with most of them above. Is is generally not a good idea to store files in the database unlike Facebook which stores thumbnails in the database.

JPro
+1  A: 

no one should mention the whole don't store files in a db to flickr. :)

Storing files, even large ones, in the DB is a question about your hardware more than a programming practice. if your server (or server farm) can handle the business there's no real disadvantage to it, and there are advantages. the principal one being that files in a db aren't "stuck" to the server. files go wherever the database goes, and are replicated as required.

as with everything, no one answer is correct.. you have to make your best decision based on your actual project requirements and future plans.

ruzz