Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Best database setup for image uploads

Posted on 2016-11-01
6
Medium Priority
?
91 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

610 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