I am trying to code my own simple AJAX image upload script via jQuery. I have found some plugins but they are way too customized for what’s needed, and I cannot get any of them working properly.
I just want to somehow detect when the user drags and drops an image onto the page. From there I’m sure it’s not hard to upload that data and move into a /cache/ directory and allow for further options..
but right now I’m totally stuck with the drag/drop functionality. Literally no idea how I should approach this. What kind of event handler is needed? Will I need to custom code my own event handler? Any advice would be more than appreciated
Drag’n’drop requires a HTML5 browser – but that’s pretty much all of them now.
I’d recommend not starting from scratch as there’s quite a bit of code needed – I quite like this wrapper that implements it as a jQuery plugin.
http://www.github.com/weixiyen/jquery-filedrop
After defining an element in the document with class div, you can initialise it to accept dropped files with:
The bit of the web page that accepts uploads has this HTML.
The file drop works on the outer <div> but it’s nice to make a nice big target that says ‘DROP HERE’ so that users aren’t confused about where they need to drop the file.