title: Image id not showing
body: <p>Take a look below code I'm trying to alert the value of <code>i</code> inside the <code>reader.onloadend</code> it's not showing properly, It's showing max value of <code>i</code>, i.e if <code>i</code> add 3 images <code>i</code> alerting only three it should show 0,1 and 3.                    </p>
  
  <pre><code>$("#files2").change(function()
  {
      var src=$("#files2").val();
      if(src!="")
      {
          formdata= new FormData();
          var numfiles=this.files.length;
          var i, file, progress, size;
          for(i=0;i&lt;numfiles;i++)
          { 
          //alert(i);
              file = this.files[i];
              size = this.files[i].size;
              name = this.files[i].name;
              if (!!file.type.match(/image.*/))
              {
                  if((Math.round(size))&lt;=(1024*1024))
                  {
                      var reader = new FileReader();
                      reader.readAsDataURL(file);
                      $("#preview").show();
                      $('#preview').html("");
                      //&lt;img src="img/remove.png"/&gt;
                      //style='margin-left: -16px;margin-top: -6px;'
                      alert(i);
                      reader.onloadend = function(e)
                      {
  
                      var image = $('&lt;img id="im'+i+'" style="float:left; height: 150px; width: 125px; margin-left: 5px; margin-right: 10px; margin-bottom: 10px;"&gt;').attr('src',e.target.result);
                      var image1 = $('&lt;img onclick="$(this).remove();$("#im1").remove();" style=" margin-left: -25px;margin-top: -1px;z-index: 1;position: absolute; "&gt;').attr('src','img/remove.png');
  
                      $(image).appendTo('#preview');
                      $(image1).appendTo('#preview');
  
                      };
                      formdata.append("files2[]", file);
                      if(i==(numfiles-1))
                      {
                          $(".nextim").click(function(){
                              $.ajax(
                          {
                              url: "upload.php?contactid=&lt;?php echo $id1; ?&gt;&amp;postid=&lt;?php echo $id2; ?&gt;",
                              type: "POST",
                              data: formdata,
                              processData: false,
                              contentType: false,
                              success: function(res)
                              {
                                  if(res!="0")
                                      $("#info").html("Successfully Uploaded");
                                  else
                                      $("#info").html("Error in upload. Retry");
                              }
                          });
                          return false;
                          });
                      }
                  }
                  else
                  {
                      $("#info").html(name+"Size limit exceeded");
                      $("#preview").hide();
                      return;
                  }
              }
              else
              {
                  $("#info").html(name+"Not image file");
                  $("#preview").hide();
                  return;
              }
          }
      }
      else
      {
          $("#info").html("Select an image file");
          $("#preview").hide();
          return;
      }
      return false;
  });
  </code></pre>