Upload php image

where is it better to upload images? Database or web directory? And why?

+4
source share
5 answers

You should only store images in your database if you need a specific need, such as security, or as an absolute death for the need to store all user data in the database.

In addition, getting large files into databases is usually not worth the trouble. Storing and retrieving a file is much more difficult to implement, and updating / updating / converting databases has many more things that could go wrong.

+4
source

I do not see that there is an advantage to storing images in a database. There is no inherent security in this. Files for the file system store your images there.

+2
source

I donโ€™t think you can โ€œuploadโ€ an image to a database. You can save the value of the image string in the database and pass it through the "header (" Content-Type ") later. This saves space on your web server, but obviously takes up space in your database.

If I were you, I would boot into the web directory, so you will have an image for regularly requesting the URL later. If you do not have it in the regular directory, you will need to connect to the database every time you request an image and then transfer it.

0
source

Good. It depends on your requirement. If you consider security as a serious problem, then you should definitely save it in db, otherwise you will not be able to save images in db.

Also, removing images from the database is quite difficult, since binary data is stored in the database samples. So if you have a specific need, then just store the images in the database, other wise saved images in the directory will be fine.

0
source

As you can see, there are many reasons to use / why not use a database to store images. Personally, I prefer not to use a database to store files (images, documents, etc.), unless I am ordered to store them.

- Sometimes you get tired and fasten the request, something like "SELECT * FROM images", this will kill the server if the database contains too many images with a huge size (2 MB or more). - Security issue: you can still save files to disk and still be safe, how? Save files well outside the web directory, whenever a file is requested, read the file and pass it to the user. -If you accidentally use MySQL: if your database got to a large one (say 2-3 GB) and you use shared hosting, good luck in creating a backup or trying to restore this image database.

This is just my point.

0
source

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


All Articles