I was wondering the best option to build a website that will allow an user to send photos to be displayed on a open part of the site and I don’t know if I should build a database in mysql to receive those photos and then to this table to be pushed on the screen and it grows. Is there any other options? Like getting these photos on a folder and then make a system to get them as I’d do if programming normal html and css. To get these photos as a blob inside the table may be an opinion, but there might be some other way that might be interesting to know about. Thanks guys!
Share
First thing is you should never ever save photos into your database.
Database should only hold information about images, where are they stored, whats their size etc…
First solution:
You can save uploaded photos in some folder on your server, and then when you want to show those photos, just read content of that folder to get information about uploaded photos and show them on your web. You can list content of a folder easily with PHP. And this way you have images location information and you can add them to your HTML easily. You can have one folder per user if you want to. And then you can fetch user from lets say session, and you know that his images are saved into /uploads/images/{user}/
Second solution:
Even better way would be to upload photos to your server folder, but when uploading photos you can save information about photos into database. So when you want to show photos just go through database table then has information about uploaded photos. You would save everything you need about photos in that table, like, photo_path, photo_size, photo_dimensions, photo_uploader, photo_category etc…
This way you can easily cache those information and speed up your site if needed.
The first solution is not good for high traffic sites since you would have to list all the folders/images on every page request, and this can be slow.
Anyway, images should go into your server folder, and you would either use PHP functions to read that folder for information like how many images are in the folder, whats their size etc… you can do all that with PHP. Or even better, before you upload image to a folder, inspect every image and save that information into database. If you go with the first solution, you dont even need to use database, but this could bite you if your site grows and you want to improve performance.