skip to Main Content

What’s the best approach to store multiple images in database?

Upon browsing and searching for solution and approaches I found 2 options

first one is take the file name and concatenate and separate them using either comma or |
but I’m having doubts since I think that’s messy and would produce errors later in the system

second is I make another table for images and add foreign key (post_id) to know which post it belongs.

Any suggestion will be appreciated.

2

Answers


  1. Both methods work well. I would place the second.

    It can also provide convenience when using some image upload plugins (filepond, dropzone etc.).

    If I were to choose the first method, I would save the serialized arrays (with serialize()) for better bet.

    Login or Signup to reply.
  2. Second one because it is normalized and you can have a better DX with that, No weird implementation to edit or any manipulation of post.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search