I need to loop this on the input of several files:
var reader = new FileReader(); reader.onload = function (e) { $('#pprev_0') .attr('src', e.target.result); }; reader.readAsDataURL(input.files[0]);
I tried this, but it does not work:
var fileCount = 0; $("input[name='files[]']").each(function() { var reader = new FileReader(); reader.onload = function (e) { $('#pprev_'+fileCount) .attr('src', e.target.result) .css("display","block"); }; reader.readAsDataURL(input.files[fileCount]); fileCount++; });
alert () on output fileCount once 0 for multiple file selection. no additional warnings. If I take numbers instead of the fileCount var code in the code, it works in position. R.G. input.files [2] ...
Any idea?
source share