1

This question already has an answer here:

I am trying to build my own little eCommerce CMS, and i want the expert opinion on how to handle multiple uploaded files (images).

For Example:

A user adds a new item, fills the necessary form data and selects (nth) number of images and submits. I want to know how should i handle those images data into MySQL.

one thought i have in mind is that i create a separate table item_images Where i assign an ID or something like Item Code which inputs by the user and that Item Code will be the Identification for all the images?

PS: I dont want to upload Images directly to the Database, Just the paths/links.

Please advice.

marked as duplicate by user22815, gnat, user40980, GlenH7, Dan Pichelman Mar 3 '15 at 15:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • yes, and also updated my question. – XeBii Feb 27 '15 at 5:06
  • 1
    This is a solved problem: have you looked into how any of the various free CMS packages work? MediaWiki does this for example. – user22815 Feb 27 '15 at 5:12
  • yeah thats good but Can you tell me in a simple way? – XeBii Feb 27 '15 at 5:17
  • 1
    Building your own CMS isn't a simple task. – reformed Feb 27 '15 at 5:31
  • That's what i thought, but i want to do this any ways it'll help me learning more (like this issue im having) – XeBii Feb 27 '15 at 5:56
2

You could do this by creating 2 additional tables:

Table Images ( ImageID int, ImagePath varchar )

Table ImagesXUsers ( UserID int, ImageID int ) (or ImagesXPages or whatever it is you need to associate these images with)

Whenever images are uploaded, they are inserted into the Images table, and are appropriately associated with the user account via the ImagesXUsers table.

An example query for retrieving all the images for a given user account could be the following:

SELECT i.ImageID, i.ImagePath
FROM Images i
JOIN ImagesXUsers u ON
    u.ImageID = i.ImageID AND
    u.UserID = {whatever user is logged in}
  • No problem. Are you familiar with database normalization? – reformed Feb 27 '15 at 6:21
  • Not really :( no – XeBii Feb 27 '15 at 6:27
  • I highly recommend looking into it, it will save you alot of headaches when designing and dealing with a database. Check this out: studytonight.com/dbms/database-normalization.php – reformed Feb 27 '15 at 6:33
  • Thank you. I'm definitely going to read that thoroughly. – XeBii Feb 27 '15 at 10:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.