When user upload image I resize that image in 3 different sizes. I can’t decide what is better option:
1) Save image path in one column in database like: User9876/ImageName and extension in another column. When I get user profile data from database I have business object with three properties for different image size. And in code I fill this properties by adding extension to image path from database like:
User9876/ImageName_Original.jpg
User9876/ImageName_Small.jpg
User9876/ImageName_Smallest.jpg
2) Or it is better to have three columns in database for each size?
Couple of recommendations:
Don’t store the extension separately, unless you plan on querying for particular extensions. Just adds more complexity for no real gain.
I would store the image size code as an id in your images table. This way you can update/edit image codes without having to run an update statement on your entire table.
create table image (
idint(11) unsigned not null auto_increment,pathvarchar(255) not null,size_code_idsmallint(3) not null,PRIMARY KEY (
id))Engine=MyISAM Default Charset=utf8;
Example row:
This design will allow you to query for the ‘small’ image without having to parse the filename, yet you can still make the distinction of a small image from medium and original images on the filesystem.