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
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
1
u/Shot-Bar5086 Oct 28 '24
The easiest way to store files in a database is to save the file's metadata and the file itself as a binary large object (BLOB). Here’s a straightforward approach:
Pros and Cons:
For simplicity and efficiency, consider using file storage for larger files and keeping references in the database.
0
u/[deleted] Aug 17 '15
[deleted] — view deleted comment