Vadiklk
Vadiklk

Reputation: 3764

Should I save image url in the data base?

Here is the situation:

I want to add the ability to add/edit recommendations in my new site. I want that every recommendation will have a photo, which if uploaded is shown that way and if not, shown other default image.

The question is, should I save the url of the image I upload in the database? Or should my getImage function just return the url to an image as it is by the unique id of the recommendation (like "/photos/$id.jpg")?

Upvotes: 0

Views: 170

Answers (1)

shanethehat
shanethehat

Reputation: 15570

Rewritten for clarity and detail...

I think that as long as the additional weight in your database is not an issue (and you state that it is not) then using a descriptive file name is better than an id number for these reasons:

SEO: File names are one of the factors that search engines use when indexing your site's content. Although it is only a small part, and for images the alt, title and description properties carry more weight, it makes no sense to me to deliberately omit potential data unnecessarily.

Usability: From you own point of view, if you need to update an image at a later date it is going to make your life easier if the file names are easy to read. This will save you time that you would otherwise need to check which file you need to work with.

Upvotes: 1

Related Questions