How can I insert an image in MySQL and then retrieve it using PHP?
I have limited experience in either area, and I could use a little code to get me started in figuring this out.
How can I insert an image in MySQL and then retrieve it using PHP?
I have limited experience in either area, and I could use a little code to get me started in figuring this out.
Personally i wouldnt store the image in the database, Instead put it in a folder not accessable from outside, and use the database for keeping track of its location. keeps database size down and you can just include it by using PHP. There would be no way without PHP to access that image then
instead of storing image in the database, store it in your phone and pc and just use its path as it will save your database
I agree with the basic concept of @Andomar, but would store the actual images on disk to avoid storing large data in SQL. Remember that a large field is 255 chars in SQL. So you'll need to store the images files in Blobs, which work well when you only have a small amount rows (think: hundreds, not millions). The reasoning is complex, but it's good practice. Here's how I know:
I wrote a large project that stores lots (and lots) of images. Always store them on disk to save yourself a SQL headache. If you're worried about a DB corruption leaving you with images you can't "rebuild" into a database, there's an easy fix (besides backing up your SQL table(s) )
Store your images in a directory tree with directory names that make sense for humans and parsing. So storing it by time might look like "/year/month/day/picture.jpg" or by user "/user_id/picture.jpg". Use this as a concept, and just store the path in SQL. This will make your SQL table small and often cacheable and allow your SQL table to be on one server, and your images to be stored on another "server" such as AWS's S3.
If you're really paranoid, you can store a file called "{image_name)_meta.json" in the same directory as the image itself. Fill it with meta data about the image that you normally store in the DB table. If the table corrupts, you can write a a little function that walks through the tree and rebuilds the table from the JSON files. This of course will take up more disk space, but it's pretty cheap (think: AWS's S3).
There are lots of ways to solve this, but storing large amounts of images in any SQL-type table is rarely a good idea. Exceptions would be displaying hundreds at once, or perhaps lighting-quick retrieval times (instead of sub-second).
Good luck with your project!