Hello. Let's say I have image.jpg on my server's root and I have a MySql database where I want to insert this image to (not just it's URL or filename, but the whole image's contents, and be able to retrieve it back and show it to the user without breaking). How do I process this with PHP? $contents=fread("image.jpg"); the file and the usual mysql_query("INSERT INTO blabla (img) VALUES".$contents);? I am guessing this will just insert some random string junk that will not construct the original image when read back and shown to the browser. Regards!
Doing this is bad database structure; it will bloat and slow down your application in the end so try to avoid it.... Is there any reason why you must store the *file* and not its location?
By their very nature, databases grow in size..... 'avoid problems later by preventing them to start with'.
Remember to mysql_string_escapce (? check name) your $contents first..... If you have allot of images sometimes your better of keeping them on the FILE SYSTEM with a path in the database
I am asking because I will store a lot of small images (a few kilobytes each). Is it better to store them as files instead of in the database? Also, nobody answered my question specifically. How do I read the contents of an image and save it in a way that I could retrieve the original later? The one thing that @kmap pointed out is that the field type must be "BLOB" instead of "VARCHAR" for example, is that correct?
http://www.greywyvern.com/code/php/binary2base64 Base64 it and insert it as a text string in your database. Pull it from there.