E
E
elailasou2015-01-27 11:17:45
PHP
elailasou, 2015-01-27 11:17:45

Is it advisable to store images in a database?

I use MySQL, PHP.
I am making a posting system, the pictures of each post need to be saved somewhere.
Is it advisable to store images in a database? Or is it better to implement storage in folders with files?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
M
Maxim Kudryavtsev, 2015-01-27
@kumaxim

It’s bad to store pictures in the database, and here’s why.
If the picture is in the database, then in order to pull it out, you need a php script that will send a request to retrieve it. Dynamic content will be generated, Apache is running.
If the picture is in a folder, then to display it, simply refer to it by URL. Here you can do without a script, therefore only nginx can work.
What is the point - nginx eats MUCH fewer resources compared to apache. You can google the statistics.
The only limitation when using storage in folders is that for *nix, a folder cannot contain more than 42-something thousand files (I can be wrong with the number, but that's not the point), so consider this aspect.

E
Eugene, 2015-01-27
@Nc_Soft

impractical

R
raiboon, 2015-01-27
@raiboon

It's terrible to store images in MySQL, and use MySQL when you have Postgres.
In general, in the database, then in theory it is possible, in the same riak or mong - no problem.

A
Anton Kuzmichev, 2015-01-27
@Assargin

Both methods have their advantages and disadvantages, but still storing as simple files is more organic. This is static that needs to be given to the user without the participation of scripts.

S
Sharov Dmitry, 2015-01-27
@vlom88

the picture itself in the folder, additional information in the database

Z
zed, 2015-01-27
@zedxxx

Is it advisable to store images in a database?

Depends on the number of pictures. Pictures can be stored in the file system or even in the same database as the data, but this, IMHO, is an extreme case if there are not very many pictures. BUT if you write your instagram, then you definitely need your own database for pictures. Note - the database is for pictures, not for data + pictures. Those. these things need to be carried to different bases. And if it is better to store data in SQL, then pictures can be added in NoSQL.
This is actually a very difficult question - how to optimally store binary data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question