First, I noticed there are many questions regarding this, lots marked as duplicate.
I eventually came to this one.
And the accepted answer for that question although partially solves my question, it doesn’t answer all of it.
My question is, a user uploads an image. I store the path in the database and the image file in the file system.
However, I make 3 copies of that image (large-, medium- and small-sized). So all in all I have 4 images – original, large, medium, small.
Should I store all 4 paths in the database, like so
ID | original | large | medium | small |
----+--------------------+-----------------+-----------------+----------------+
1 | /path/to/original | /path/to/large/ | /path/to/medium | /path/to/small |
or just store the original’s path, and give the other 3 a naming convention, like so:
car.jpg, car.jpg, large-car.jpg, medium-car.jpg, small-car.jpg?
I feel this way would be less heavy on the database, and that if later, I wanted to add another size (ie. extra small) I wouldn’t have to moditfy the database.
If all the images in a given row live in the same place, I’d say their base path should be its own column (rather than re-deriving the base path from the original image’s full path all the time).
If all the images in the database live in the same place, don’t store the base path in this table at all; have it in code, or in a global configuration table.