ketanco wrote:what is the reason though that it is not recommended?
A DBMS, IMO, isn't commonly used to store binary data; that's what the server's file system is used for. File systems are basically databases optimized for storing and retrieving binary data in the form of files, so why not use the right tool for the right job?
ketanco wrote:Isn't this easier this way, instead of having to go through the extra step of uploading the image to the dir?
Not at all, no. First of all, you still have to upload the file to a folder - how else can you use the file unless the server stores it somewhere first?
Second, once you receive the file, it's as easy as calling [man]move_uploaded_file/man to move the temporary file into its permanent location. THe hardest part of the process is deciding where you want to store the file, in my opinion.
ketanco wrote:BLOB A string with a maximum length of 65535 characters.
does it mean the image can be max 64kb?
also i saw another data type:
LONGBLOB A string with a maximum length of 4294967295 characters.
so should i use this one?
That all looks correct to me. As for your question, you have to answer that for yourself. Figure out the maximum size of whatever it is you're storing and pick whichever type of field will fit that amount of data (usually plus a little extra padding, just in case there's a random file that comes through that is a little larger than you normally expect).
EDIT: Actually, if you want to get technical, the MySQL manual for BLOB fields states that the length must be less than, not less than or equal to, 216. In other words, you're actually limited to 1 byte short of 64kb.
ketanco wrote:It also says: "These types can store a large piece of data information, but they are also processed much slower. "
is that why you dont recommend ?
I don't recommend storing the binary files in the DB for a couple of reasons. One of them I mentioned above; a file system is a database designed to catalog and store files. Again, just seems like the right tool for the right job IMO. If you've got a screw, would you pick up a screwdriver or a hammer? In the end, you could probably make both tools work, but obviously one of them would be more suitable for the task.
ketanco wrote:Finally, just wondering, can I also use
<input name='new_image' id='new_image' type='file' />
to upload the image to the db?
You would use something along the lines of that regardless of where you store the file. Unless you have some sort of fancy Java applet to upload files, then yes, you'd normally use an INPUT type="file" HTML element.