开发者

Store an image name and extension in DB?

If a user uploads an avatar and I create:

1. example.png
2. example_large.png
3. example_small.png

(note: jpg开发者_JAVA百科 and png are allowed)

Is it best to store the raw image name ('example' in this case) and the image extension in two separate columns?

EDIT

for example:

    image_name | image_ext
    -----------------------
    example    | .png

END EDIT

Or maybe use a regex to remove the extension and then add it back (with the desired size: large, thumb, etc)?

Or maybe I'm insane and should just change my naming convention...


I suppose if you wanted to query on the extension i.e. give me all the 'large' images then there would be value in storing the extension in a separate column. If you have no reason to query, sort, report etc on the extension that just keep it in one.

In short if the extension itself is significant than an argument can be made for storing it separately.

EDIT

Even with your edit the answer is the same if the extension is a significant piece of data i.e. you want to query on all "png" then store them separately if its not then just store them together.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜