|
Best way of serving images?
I have a website which serves images in various sizes (e.g. wikipedia allows you to view the same image in different sizes). The images are uploaded by the users of the site.
Currently, I use PHP to process the uploaded images and store them in various sizes in a database (e.g. small/medium/large).
What is the best way to serve the images? I can think of:
1) retrieve each image from the database each time it is required. (*** This is the way I currently do it ***)
2) store the images as files in a folder in the public web directory and simply link to them.
3) Using the database-retrieval method, keep a store of previously-requested images in $_SESSION and serve them from $_SESSION each time they are required.
Option 2 is probably the most efficient, but I don't like the idea of having a writeable folder in the public web directory. Also, I suspect that doing this would leave the folder open to site-scrapers who could simply retrieve every image stored there.
|