A
A
Anchor002015-09-17 23:43:00
PHP
Anchor00, 2015-09-17 23:43:00

Should I store image titles in the database?

In the catalog script, product images are named using the mask {id}{alias}{№}.{ext}. The question arises, is it even worth making a field in the products table for images? (they after all are named on a strict template) What reefs/nuances can be.
UPD. Guys, there is an important nuance - this is a boxed script

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Litvinenko, 2015-09-18
@Anchor00

No, it's still very desirable. what I will describe is not the only correct implementation, but quite convenient.
You will have a lot of pictures, as I understand it, it is also likely that you will have different sizes of the loaded picture saved, and possibly different options with superimposed effects.
Also, there cannot be many files in a folder, there are some features of the file system, a lot of pictures in one folder - it will slow down its work.
Let's say the picture is called 123.png and its hash is e621fccb4c38d568669432b004a50f59.
You can make the path to the image
/img/621/fcc/b4c/38d568669432b004a50f59/original.png
What will it give?
1. The name of the picture is taken from the database, if two identical pictures are uploaded, their hash will match, you will avoid file duplication.
2. You can save different versions of the picture, for example:
/img/621/fcc/b4c/38d568669432b004a50f59/original.png is the original, and
/img/621/fcc/b4c/38d568669432b004a50f59/size_l.png is a reduced copy of
/img/ 621/fcc/b4c/38d568669432b004a50f59/size_l_stamp.png - small copy + watermark
3. There will never be more than 4096 files in the folder, since the folder name is part of the hash

M
My joy, 2015-09-17
@t-alexashka

No, it is not necessary , if you always follow this pattern, there is no need to store the address in the database. Even if you want to remake the template, or the storage algorithm in general, knowing the original mask, you can handle it. I also store images for ads on the site, by the name of the folder with the id of the ad itself. And the base does not know about it. And it does not need to store extra 20-30 characters (it is especially noticeable if there are indexes, and if there are more than 1.6 million records of data).

A
Alejandro Esquire, 2015-09-17
@A1ejandro

In general, how much easier it would be if you store images in external files, with the names {id}.{ext}, if only one image could correspond to one base object. The base in general could not be increased by a single byte. And it can correspond to one, if {ext} is taken equal to pdf, and different images would simply be placed on different pdf pages. And convenient operator work with images would be realized by simple regeneration of pdf from page-by-page graphic files. I went down this path, but I have the specifics of a simple Electronic Archive. It probably has nothing to do with what you're trying to solve....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question