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.
5
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}
4