snytkine / LampCMS

Open source Question and Answer program similar to StackOverflow and Quora in PHP + MongoDB. Follow @snytkine on Twitter
http://support.lampcms.com
323 stars 104 forks source link

Add image upload function #53

Open snytkine opened 13 years ago

snytkine commented 13 years ago

Add Image upload to YUI Editor's Image widget. Base on this script http://allmybrain.com/wp-content/uploads/2007/10/yui-image-uploader26.js

demo: http://allmybrain.com/2009/07/01/example-image-upload-with-yui-rich-text-editor-270/

but must rewrite to use YUI3 functions instead and just make it better... May add "Uploading progress" spinner or spinner bar from our "Loading please wait" widget and dismiss it when upload is complete and we either receive IO:success or IO:timeout or error notifications!

Must write php controller to handle uploaded images - measure and resize if necessary and return json with image dimensions and path (web path)

Also Image controller should record to Mongo ImageID, path, uid - id of user (uploader/owner), timestamp, image type Also fire some events like on ImageUpload and watch for cancelled events. Later can add auto-watermarking support.

snytkine commented 12 years ago

Now that JS side of image upload is functional, some practical details: How to create path to image? 2 dirs: orig, web

1) Save orig 2) Resize : if does not need resizing then just return path to orig else create websize and return path to it. This way the javascript can be written that by examining the path to image will know that it's a path to a resized image and a larger size original exists on the server, so can offer to open original in new window or some type of JS based modal

To create path need to use IMAGE_UPLOADS collection in order to generate ids? Can also use combination of userid + timestamp. That will work well.

19232/11232142321

Something like that...

Also would be nice to check reputation before allowing image upload the JS for upload action will be added based on reputation and image parser will also check the reputation

Also need a way to prevent upload DOS attack where tons of files, even worse - actual large size images are uploaded rapidly, overloading the server because image resizing is memory-intensive.

So need to check for IP based flood, userID based flood. Best is not to allow non-registered users to upload images at all.