views:

22

answers:

2

So I have a simple Apache with MySql I am developing a PHP app. I have Users Table in my DB. I vant to let them store Icons.

My question Is what's the best way of attaching such data as icons (100-250kb's) to DB - Is it beter to store them Inside DB or store them as File and some how attaching links to icons into DB. What's the best way? Are there any classes that automate this process (of attaching such data to DB)?

+2  A: 

I would store them as files, and reference them from the database. I made the mistake of storing images in the database itself (as BLOB I think) and regretted it the next day when db-connections had to stay opened longer, images didn't cache when I went to view them multiple times, etc.

I would only suggest storing the image itself in the database if it's absolutely necessary. If you're going to be using these images frequently, and showing them in multiple placed, I would suggest storing filepaths only in the database, and keeping the images in the filesystem.

Related: Storing Images in DB - Yea or Nay?

Jonathan Sampson
+2  A: 

easier to keep the icon as a file and store the path in the db

the most efficient way to serve the image is by having the web server transmit a file directly from disk, so you may as well keep it there. having it in the db would make serving take longer and would have little purpose (there's no need to search through the binary data of the image and this would increase the size of each row in the db by a large amount, making read/iteration operations much less efficient because of the reduced locality)