I have this code which works for uploading multiple files (images). However, it seems inefficient due to having to a function for every single file upload (for 2 uploads, but there will be about 12 in total).
function readURL1(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
jQuery('#div1').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
function readURL2(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
jQuery('#div2').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
Then...
jQuery("#img1").change(function(){
readURL1(this);
});
jQuery("#img2").change(function(){
readURL2(this);
});