2

What is the best technique to save images in the mysql database.Should I save images as blob data or save it in directories.The images will be showed every time the user visits his or her profile. -Thanks in advance.

Tanbir Ahmed
  • 320
  • 1
  • 4
  • 11

2 Answers2

8

The best technique would be to save them in the file-system and save their paths in the database.

The database is meant for data, the file-system for files.


The technique I used in the past to make sure there are no duplicates was to hash the contents of the file and save it as the result, so I get something like:

42efb15825666918118ba72128195246dbae4976.jpg

The actual name is saved in the database. This was, the chance of having duplicates is negligible.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
4

The best technique is what Truth said, in addition, to guarantee that your images will have a unique name, use the current timestamp to rename them in your directory.

Ahmed Laatabi
  • 907
  • 1
  • 8
  • 21