Storing the imagepath in the database

this post could be made as well to the database forum,nonetheless I chose to make it here cause the solution may be related to php and not to the database.

I am making a blog and each blog article will have one image associated with,one big and one small.The small will be for previewing the article and the big when the article will be displayed fully to the user.

The imagepath of the small image will be stored in the database,but since we have 2 versions here of the same image, I assume there must be two columns storing the image path(one column for storing the image path of the small image and one column storing the image path of the big image)…unless there is another solution that is not db related.

In which case I am willing to hear it.

If you use a naming convention you might be able to get away with storing the name once only. You could store your main image in the directory images and the smaller version in thumbs, for example, or name your images blogpost-xxx.jpg and blogpost-xxx-small.jpg.

… assuming I’ve understood your question…

3 Likes

I would do something similar to @Gandalf and he may have meant to explain it this way.

Both images will have the same name
Big image will be in a folder called big
Thumbnail would be in a folder called thumbs

You only then need to change the path folder name depending on what image you want:

<img src="big/image.jpg"> or <img src="thumbs/image.jpg">

3 Likes

So I am assuming all these mean that one column will be needed in the db table after all.

Yes the one column would contain image.jpg and it would in fact be a variable containing the data pulled from the database. I know some forums leave off the extension as well. I assume they convert all image uploads to one file type.

Unless you store the images related to the blogpost somehow - like blogpost-123.jpg for the blog post with ID of 123

I prefer unique image file names to prevent duplicates and also allow multiple use of images.

True, but I was mentioning it purely based on the initial requirements - one image per post (if you tie the image name to the blog post id, it’s going to be unique)

1 Like

Plus it won’t even need 1 column in the database, as it can be recognised by the ID or date or whatever. The down side being maybe a less descriptive filename.

3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.