A
A
Alexey2015-12-03 01:47:10
PHP
Alexey, 2015-12-03 01:47:10

What is the best way to store pictures?

I have been thinking about it for several weeks now, I can’t decide how to properly and best store pictures on a culinary site.
There is a recipe, it has a main picture and steps for the recipe. an average of 10 pictures per recipe. Each picture has a reduced copy, medium and original. Is it correct from the point of view of seo and some future subtleties, will it store pictures in such directories and with the title of the article in transliteration.

/uploads/images/id_post/thumb/tort_minutka.jpg
/uploads/images/id_post/main/tort_minutka.jpg
/uploads/images/id_post/original/tort_minutka.jpg

From my point of view, this is convenient, because when deleting / changing an article, you can always access the directory with its id and delete the necessary files from it. But it turns out that there /uploads/images/will be a huge number of folders with article ids in the directory.
Again... Store pictures in the database in a separate table or create a field with the name of the picture in the table with recipe steps, and store the main picture in the field with the recipe itself?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin, 2015-12-03
@unity_ultra_hardcore

It is better to name the folder not as id, but as some simple hash function from this id. Moreover, do not put everything on one level, but distribute them into 2-3. Below is an example for an article with id=123

md5(123) = 202cb962ac59075b964b07152d234b70
берем первый символ хеша - 2, создаем папку "2" в /uploads/images
берем второй символ хеша - 0, создаем папку "0" в /uploads/images/2
создаем папку "202cb962ac59075b964b07152d234b70" в /uploads/images/2/0/
кладём в /uploads/images/2/0/202cb962ac59075b964b07152d234b70 нужные файлы

The advantage of this solution is that, due to the hash function of the folders, there will be a fixed number and the files will be relatively evenly spread over them. If there are a lot of files, you can add another level. It will not be difficult to calculate this path programmatically if the method for calculating it is in one place.

S
Sergey Eremin, 2015-12-03
@Sergei_Erjemin

I think it's more logical:

/uploads/images/id_post/tort_minutka.thumb.jpg
/uploads/images/id_post/tort_minutka.main.jpg
/uploads/images/id_post/tort_minutka.original.jpg

Why produce folders? And it’s also much easier to detect the lack of pictures with the eye ...

S
Sergey, 2015-12-03
@gangstarcj

Generally normal. The fact that there will be a lot of folders, you can not worry

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question