Image storage in MySQL

software development

#1

I’m looking at storing images in a MySQL database and I had a few questions for others that have done this.

  1. what are the upload_max_filesize , max_execution_time and post_max_size parameters for Dreamhost’s PHP configuration.

  2. How much of a performance hit will I see Vs traditional file storage…

  3. Where does dreamhost stand on using Databases for image storage (mostly 10-20k files with a limit of 200k)


#2

I’m sorry that this is not a direct reply.

Our site has many images that are pulled from mySQL, but we simply put the link in mySQL. The graphic itself is loaded onto our site normally. This is very quick, and keeps the database clean and quick.

Jeff
www.walltowallstencils.com


#3

I’d have to agree with Jeff. It’s actually much more efficient to store the images in a special directory somewhere, and reference them by ID, etc.

It gets slightly more troublesome when you have images that you don’t necessarily want users to be able to “browse” under your DocumentRoot. I ran into that problem myself, where I want to restrict access to the images, but don’t want to store them in the database either. I’m not sure how to resolve this issue without writing some kind of simple client-server app to supply the images upon valid requests. Any suggestions?

–Brad Barkhouse
Be a Contender!
http://www.beacontender.com
brad.barkhouse@beacontender.com


#4

First of all, you can turn off directory indexing for the images directory (or just put a blank index.html file in there).

If you want to stop people from just randomly guessing the url an image is at, you could encrypt all the file names (e.g. , make bird.jpg 656385f55d3526df.jpg):

mysql> select password(‘bird’);
±-----------------+
| password(‘bird’) |
±-----------------+
| 656385f55d3526df |
±-----------------+

and then store the encrypted names in your database.

You can’t of course stop people from downloading any image you show them on a web page (they have to download it to see it!), but this should stop people from getting any images you haven’t explicitly displayed to them!

josh!


#5

You could also use mod_rewrite to restrict access to those images to requests referred from your site.

This is a bit tricky though.


#6

I agree here as well. I would store images in a directory and reference them from mySQL. Much…Much…Quicker

Your database could get “huge” if you stored all of your pics in binary mode. (Might be fine for a few hundred pics … anything over that … mmm)

Neal