r/web_dev • u/kamereonesec • Aug 17 '15
Store an image file in a database
I am fairly new to web development and I have a form that users fill out and everything is getting stored to a mysql db. One of the form inputs is a file upload. I want to allow users to be able to submit images.
I know that allowing users to upload files is not the best practice but it is kind of important to the goal I am trying to accomplish. I need to be able to see the image that they submit along with the rest of the information.
What is the easiest way to store files in database?
2
Upvotes
0
2
u/Sinjhin Aug 17 '15 edited Aug 17 '15
You can use blobs (Binary Large Objects), but you would need a way to retrieve and view them (another part of your website or another application entirely).
It has been a while since I have done this in PHP (which is what I assume you are using based on using a MySQL DB), but I seem to remember there being built in support for throwing blobs into a database.
https://en.wikipedia.org/wiki/Binary_large_object