简体   繁体   中英

Creating Thumbnails with GridFS + MongoDB + PHP

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?

在使用GD2将其保存到MongoDB之后,我最终只创建了自己的缩略图,然后将缩略图以及完整尺寸保存下来。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM