I am using PHP and MySQL ( via the framework Symfony 2) to create a website to show some bikes of my collection. I would like to store as much images as needed for one bike.
So I was thinking that a good way to do that is to have my Bike entity and a Picture entity and to link the Bike entity with the Picture entity by a one-to-many relation.
So, the Picture entity would look like this :
id bike_id title path
Is this the best way to do it ? Thanks a lot for your advice.
EDIT : About storing thumbnails ..
Do we have to store thumbnails version too ? As I will display many pictures in one page, I read that reducing the picture with width and height was a bad practice and it was better to store a reduced version of the picture.
So the Picture entity would rather looks like this ? :
id bike_id title path path_thumbnail
Thanks again
Yes, though you could
simplify naming the images and avoid naming conflicts by scrapping
pathand storing images as{id}.jpg.UPDATE – from your edit, I think you miss the point of what I’m saying about naming images. I suggest you don’t store any image or thumbnail URLs at all. Instead, just have a table that looks like:
Then name all your images and thumbnail files according to their
Id. In the above example, the “Cool picture” files could be called /img/277.jpg and /img/277-thumb.jpg.That way you don’t have to store lots of file names in the database, and also there won’t be any issues with file names clashing.