Creating a gallery, I faced the question: is it correct to enter the names of the image files in the MySQL database, and then, referring to the database, view them in the gallery? Is this not going to load the server? And are there any other solutions to this problem? The user will be able to change the image and their total 8 each.
- as an option: once the number of pictures is limited and not many of their names with the path, you can store one field through some separator, and insert it into the necessary places in the split code. But there are difficulties with the logic of inserting / replacing the name. - Vadim
6 answers
The only question is how many visitors to the site, and how many photos will simultaneously open on the page. If you have thousands of visitors online and each one of them has all his photos loaded at the same time, then this is at the same time several tens of thousands of queries to the database, which, of course, will load the server.
So consider yourself how big your database will be and how many users will simultaneously open photos.
But do not forget that the main load on the server will not go at the time of the file path request from the database, but when loading the picture itself.
- if several ... then the server will load as much as the disk system. - Vadim
I do not recommend storing images in the database. Store them simply in files, and write the name of the file in the database.
- Shield? Image store in files is like? In my folder they are stored. I do not know whether it is possible to store images in the database, but my names are stored there, the question was about loading the server - LordySL
- I meant to store in the folder as files and not to bother with the database. - toliklunev
- you can store pictures as you like, for example, cms OpenCMS, all stored in the database. and does not suffer from this. If you store pictures in the file system (and only the names are in the database), then you need to foresee the structure of such storage: store all files in one folder - provide huge brakes when accessing each file. - Vadim
That one database request pulling the paths to the images - what will it load the server there for?
Only in the database.
The difference between sites like this and real life is that the respondents view each problem as a new one and imagine how they would themselves solve it. But at the same time, these ideas, for obvious reasons, are not tested by practice.
If you look at all the popular scripts of photo galleries in development, it becomes clear that storing the names (paths) of files in the database is the only possible option. As soon as the ideas "how to sort the files", "and how do I rename the picture", "and how do I make comments on the photos" begin, then an insight immediately comes.
Regarding the load on the server, fetching file names from the database is no more difficult than any other request. That is, asking the question "will it not be very hard to load the server" - is it like asking "is it nothing that my car requires gasoline?" or "Can I eat soup with a spoon?". Can. Nothing. Not too much.
An application that makes queries to the database is normal .
In muscle it is natural that there is a user ID. So what's stopping you when downloading files is not to rename them under its ID? For example, the user ID - 20, then his photo will be: 20_1.jpg, 20_2.jpg, 20_N.jpg. You can store only their number in the database.
for each user, create a folder on the server with its id (for example, you can create a folder automatically during registration), store all its images in it, only the path to the image in the database (/id3243254/p_9cadc3a2.jpg)