Storing Images In MySQL
Article Comments (31 total)
Richard@Home, I have been using this method for some time now and I have had no problems. The tradeoff between this and a direcory scheme is one that I will accept. I have had no problems with the speed in a script similar to this (although I configured my SQL tables as best as I found possible).
The one thing i have to say about this is that is easier to secure. just throw down mysql_real_escape_string() and it is pretty hard for anyone to upload a malicious image (ie. PHP embedded GIFs) because the PHP is handling the headers and outputting the file before there is the chance to execute anything else.
If you are using plain old directory storage, your file sits on the webroot or wherever and can be directly downloaded via the browser. I tend to let PHP handle all my files anyways, and something like this could be integrated into an access control script, or a hotlink blocker, etc. very easily.
I have to say, so far MySQL images ftw. Great article Kevin; shoot me an email if you want to improve upon it a little, as I may have a few suggestions.
Hey, regardless of the debate, your page provided me an answer when I couldn't choose. My data was from a third party, they store it in an MS SQL database, and for the life of me I couldn't figure out how to post the image and view on a page. Thanks, thanks, thanks.




