?
Solved

Best database setup for image uploads

Posted on 2016-11-01
6
Medium Priority
?
83 Views
Last Modified: 2016-11-02
I haven't yet got to learning how to upload images in php but I need to soon for a project. I was just wondering though what the best way to store details in the database would be. For arguments sake, let's say a user can upload as many images as they want for a particular product.

Should there be a table just for product images e.g.:

image_ID
image_name
image_path
product_ID

Then the images will be associated with the product ID.

Or is there another way of doing it that would be the "norm"?
0
Comment
Question by:Black Sulfur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 41868964
I think your design pattern makes perfect sense.  You might also consider a column for image_purpose and image_order.  Purpose would let you choose a featured image, etc.  Order would let you choose which image to display first, second, last, etc.

You might want to make a Google search for the exact phrase "Should I Normalize my Database" and read the very good arguments across the spectrum of opinions.
1
 
LVL 1

Author Comment

by:Black Sulfur
ID: 41868980
Awesome, glad to know I am on the right track.

Ah, yes. I was thinking along those lines regarding the featured image but you have made it much clearer now.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 41869019
It's easy to add columns to any SQL table.  As requirements change, you can use ALTER TABLE.

You might want to learn about Laravel "Migrations" -- an interesting design.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 26

Expert Comment

by:EddieShipman
ID: 41869212
If you want to keep your storage requirements down, convert the images to base64 and save them in the DB as TEXT or VARCHAR2 data. Since you are also viewing them on the web, you can use a data url in the img tag.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 41870063
@EddieShipman:  That is a joke, right?  Base64 encoding makes strings longer.  Storing large blobs in a database makes it difficult to impossible to SELECT quickly or back up the database efficiently.  You trade one form of storage (file system) for another (database) with potentially horrible consequences, so please don't do that, unless you have identified the case where this helps.  If you've identified that case and have the numbers to back up the argument, please write an article and publish it here at E-E!

Seriously, for anyone coming across this question in the future, don't put images into a database.  Or, if you're wondering why not, just try it in a test environment and see how things work out.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 41870359
No, not a joke,  I understand that the strings are long, yes. But, converting them to strings and storing them in a TEXT or VARCHAR field in a DB is MUCH smaller than storing thousands of FILES on a server.

I was just pointing out that if he didn't have storage capabilities for the images on the server, he could use that technique to store them in the DB. Why you say horrible consequences, I don't know, Ray. It is a logical thing to do when you are limited on storage space like on some shared hosting setups and need to store a lot of images.

If you still believe I'm wrong, show me.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question