Couldn\'t come up with a good title for this.
I\'ve got a build in WordPress where I have multiple image uploads using the built in WordPress media uploader. How it\
It sure is a hard issue to solve, not very well documented, but I think use is increasing with custom post types and all... I've imho improved somewhat on Paul Gillespie's code.
var up = null;
jQuery(document).ready(function() {
up = new Uploader();
});
function Uploader() {
this.storeSendToEditor = window.send_to_editor;
this.uploadID = null;
this.imgID = null;
}
Uploader.prototype.newSendToEditor = function(html) {
imgurl = jQuery('img',html).attr('src');
jQuery("#" + this.up.uploadID).val(imgurl);
if(typeof(this.up.uploadFunc) == "function")
this.up.uploadFunc(html, imgurl, this.up.uploadID);
tb_remove();
this.up.uploadID = '';
window.send_to_editor = this.up.storeSendToEditor;
};
Uploader.prototype.upload = function(id,func){
window.send_to_editor = this.newSendToEditor;
this.uploadID = id;
this.uploadFunc = func;
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
}
Then use it by defining the custom function if you want to do more than just updating the input field for the database. I for one want to display the images within a wrapper div before uploading it.
var uploadFunc = function(html, imgurl, uploadID){
// Do whatever you want.
};
And call it almost as before:
Hope someone finds it useful!