Take the 2-minute tour ×

I'm creating a site where a client who will be selling his photography which he sells a lot of it and will probably get quite a bit of traffic. Probably around 2k-5k uniques a day. I'm using MongoDB with PHP and I read i should use GridFS to store these large files. Upwards of 2MB-5MB photos, but obviously BW will be extremely spendy (im on cloud hosting) and loading of of these images will make page loads take forever.

So, how do I create thumbnails with GridFS in PHP and MongoDB? I Googled it and I can't seem to find any real information except people pointing to: http://www.php.net/manual/en/class.mongogridfs.php

but im not sure what to do with that information. Do I need to (i hope not, this would be sort of messy):

Upload -> store original -> use GD Lib to resize original -> resized image to GridFS as a meta value to the original image?

share|improve this question
add comment

2 Answers

I ended up just creating my own thumbnails after saving it to MongoDB with GD2 and then saving the thumbnails as well alongside the full size.

share|improve this answer
add comment

One thing I did was inside a try {} catch

  1. Store original image (or your largest size) using META info like user_id, post_id, size = original, height = xxx, width = yyy
  2. Loop through all your sizes and store using the same META info as the main one, size = $size, width = xxx, height = yyy, parent_id = your original file's ID

if some exception happens (gd fails, mongo fails, etc...) then you remove the files so you don't waste storage.

share|improve this answer
add comment

Your Answer


