2
\$\begingroup\$
function uploadImages(uploader,callback1,callback2){
    uploader.onchange=function(){
        callback1()
        var reader=new FileReader()
        var i=0
        reader.onload=function(){
            var image=new Image()
            image.onload=callback2
            image.src=this.result
            if(++i < uploader.files.length) reader.readAsDataURL(uploader.files[i])
        }
        reader.readAsDataURL(uploader.files[i])
    }
}

uploader is the <input> element
callback1 is called when the user uploads something (to reset things before handling the images)
callback2 is called once per image, when it loads.

This function is being used here.

I feel like there might be a simpler way to do this.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.