Tiddo
Tiddo

Reputation: 6554

why storing image (urls) in a database [website]

What's the advantage of storing images or the path to images in a database compared to directly linking to the images from your script?

Edit: Isn't hardcoding the urls in the script also faster since you don't have to do a database lookup for every image in your webpage?

Upvotes: 1

Views: 720

Answers (3)

Your Common Sense
Your Common Sense

Reputation: 157877

It's impossible to answer to such a vague question.

What images you're talking about? Design images? photo gallery images? avatar images? It's all different cases each with own solution. Storing image names in the database will do any good for only one case out of these three, as it would be easier to group, arrange and interlink images in the gallery. While for the other cases there is not a single reason to store image names in the database.

Anyway, it's all applicable to the image names only. As there are not a single reason to store any URL or path beside image name. Url should be computational based on some rules, not hardcoded one.

Upvotes: 1

JamieHoward
JamieHoward

Reputation: 693

I do not typically do this with basic site images, but the definite advantage can be for scalability purposes. If the image is going to show up in different scripts, they can all reference to the db, thus giving you the ability to only have to change the url in one place.

Upvotes: 0

Jakub
Jakub

Reputation: 20475

Because you can dynamically alter the paths later, or be able to manipulate them, otherwise your 'script' would have to be updated EVERYWHERE (imagine your script(s) grow to large sizes).

Database makes management of data easier, and eliminates hard coding in your example in scripts.

It is never good to hard-code something.

EDIT

I just noticed you said 'storing image' I wouldn't store images in the DB, safe them for the files system and reference with the path like you stated in your question.

Upvotes: 1

Related Questions