Saving images for each user on a website (php)

Website users should be able to store images in their "area", should I store them directly in the database or create a directory for each user. Or should I have only one directory for all images and in the database store a list of images that each user owns? I'm looking for the most efficient way, which I think is a folder for each user?

+3
source share
3 answers

If you have many images per user, such as an avatar and a gallery of photos created by the user, then use separate folders with the username or hash of the user ID.

If you only save avatars, there is one large folder where the image name is the user ID or hash of the user ID.

+3
source

It depends on the number of photos.

If there is only one image per user, perhaps all in one directory.

However, if you have albums and such, there may be millions of photos with all the photos of users in one folder. This would be very slow to find. Then I would go with one folder per user.

, . .

+1

It is better to use a folder or a cache folder. You can also use the resize functions for the image, so if the user uploads a large-scale image. Your script will be able to create different sizes, for example, avatar images. And cache these images. Thus, thumbnails or avatar viewers only view the cache image of the original image. And a large image can be used for future work, for example, for a larger preview of the avatar.

0
source

Source: https://habr.com/ru/post/1740481/


All Articles