Answer the question
In order to leave comments, you need to log in
What structure do you use to store images?
I want to make a storage for images, but I can’t choose the architecture :) I have little experience, I just came up with this, namely by date for example /p/2016/12/03/23/45/12/name.jpg
but I’m going to store not only the original, and another 200, 400 px width,
how best to do all this? I use nginx to return, an example url ( http://img.project.loc/p/2016/12/03/23/45/12/name.jpg) is obtained for the same image, but only width 200 will be such a url http://img.project.loc/p/2016/12/03/23/45/12/name_2...
Maybe something is wrong, tell me :)
And how is it arranged for you?
Answer the question
In order to leave comments, you need to log in
but I'm going to store not only the original, but also 200, 400 px widthcloudinary.com
little experience, just came up with this, namely by date for example /p/2016/12/03/23/45/12/name.jpgno need to reinvent the
$directory_generator = new Krugozor_Utility_Upload_DirectoryGenerator(/* имя загруженного файла */);
// создали директорию в THUMBNAIL_150x100...
$directory = $directory_generator->create(DOCUMENTROOT_PATH . Krugozor_Registry::getInstance()->UPLOAD['THUMBNAIL_150x100']);
// отресайзили...
$creator = Krugozor_Thumbnail_Factory::create(
DOCUMENTROOT_PATH . Krugozor_Registry::getInstance()->UPLOAD['THUMBNAIL_ORIGINAL'] . $upload->getFileNameWithExtension(),
$directory . $upload->getFileNameWithoutExtension()
);
$creator->setResizedWidth(150);
$creator->setResizedHeight(100);
$creator->resizeFixed();
// http-путь до картинки
$this->getView()->path_to_image = $directory_generator->getHttpPath() . $creator->getFileNameWithExt();
/images/users/avatars/lksdhg324nk54h.jpg
/images/users/avatars/lksdhg324nk54h-200x200.jpg
/images/users/avatars/lksdhg324nk54h-400x400.jpg
/images/posts/kjnh345jkb43jb.jpg
/images/posts/kjnh345jkb43jb-200x200.jpg
/images/posts/kjnh345jkb43jb-400x400.jpg
I generate uuid - for example 39c807bc-5b1f-11e6-95a6-a3eadeba2e44
On the disk it will be like this:
images/39c807bc/5b1f/11e6/95a6
/
a3eadeba2e44.jpg
5b1f/11e6/95a6/a3eadeba2e44-preview.jpg
as well as writing to the database with the same id
here,
as they have already written more than once - the originals are in md5, the nesting of directories - two
in total gives 65536 directories with 65536 max files in each
, enough for a career
you can make a unique structure and a unique name from a hash from a file
/ images / category name(goods, redactor, user, etc.) / year / photo size('400x', '200x200', 'x1000', etc.) /hash of product id, etc. .jpg
You can select all photos of a certain size without going to
the
database
.
General form:
A hash can be formed based on a timestamp, the storage path to the file, and a "salt".
I've only recently been interested in this issue.
Let me clarify, for starters, that I use a ready-made solution for working with images, and I advise you)
I did this:
1. It is necessary to determine how many images there will be in the future of the project.
If there are 100 and after 5 years of the existence of the project, then there is no need to invent anything complicated.
If there are more, then you will need to scatter them into folders.
Roughly for myself, I figured that about 20 photos would be stored in my folder.
And in the project, I set the bar for myself at about 9000 images + their copies 300x200. and here are the calculations.
9000*2/20 = 900 folders.
In fact, 20 photos is not even enough ... But I chose this figure for personal reasons.
Generation code like this:
$rand_int = rand(1,5);
$rand_md5 = md5(str_random(rand(6,15)));
$dir = '/images/uploads/minerals/' . $rand_int . '/' . $rand_md5[0] . '/' . $rand_md5[1] . '/';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question