Pixelairport's avatar

How to save images path to different image sizes?

I create a extension which have creates differents sizes for image uploads. For example I have an avatar. The full/path/to/image.jpg is stored to my users database. Now i want to upload mulitple files to public folder. This could look like this:

public/user/3nfHGe/avatar/msne484ng.jpg public/user/3nfHGe/avatar/small/msne484ng.jpg public/user/3nfHGe/avatar/large/msne484ng.jpg

I can change the macros for building these different sizes in a config file. So in one project i maybe have 2 macros in another one i have 10.

Now I try to find the best way to save the path to images in database. Would you save each to database in a single row, or would you do another field in users and save it as array or json in database, or would you split the filename and path and do everything in code. I mean recreating the full path in a controller or repository for example?

0 likes
2 replies
ahmeddabak's avatar

since it is a configurable extension, i would not do a field for each file, also a field for each table is not recommended (it would be hard to implement and track), let the extension create its own table/ migration and store all filed in that table, each file in a row, then every model that have files can then use a trait which have all the logic to retrieve/query the different sizes.

1 like

Please or to participate in this conversation.