title: addEventListener not working for image upload
body: <p>Using addEventListner I am trying to upload image. when I upload image first time its working fine. But the second time when I am upload same image by changing image sizes its passing php image error 3 (The uploaded file was only partially uploaded).</p>
  
  <p>My code as follows:</p>
  
  <pre><code>jQuery('document').ready(function(){
      var input = document.getElementById("upimg");
  
      var formdata = false;
  
      if (window.FormData) {
          formdata = new FormData();
      }
  
      if(input != null) {
  
          input.addEventListener("change", function (evt) {
  
          var i = 0, len = this.files.length, img, reader, file;
          for ( ; i &lt; len; i++ ) {
              file = this.files[i];
              if (!!file.type.match(/image.*/)) {
                  if (formdata) {
                      formdata.append("image", file);
                      formdata.append("appid",appid);
                      formdata.append("deviceid",$('#selected_device_id').val());
                      formdata.append("selected_device_id",$('#selected_device_id').val());
                      formdata.append("selected_parentid",$('#selected_parentid').val());
                      formdata.append("selected_propertyid",$('#selected_propertyid').val());
                      formdata.append("selected_propertyname",$('#selected_propertyname').val());
                      formdata.append("opacity",$('#opt1').val());
                      if($('#selected_parentid').val() == '12')
                      {formdata.append("ratio",'240x320');}
                      if($('#selected_parentid').val() == '15')
                      {formdata.append("ratio",'320x480');}
                      if($('#selected_parentid').val() == '18')
                      {formdata.append("ratio",'480x800');}
                      if($('#selected_parentid').val() == '31')
                      {formdata.append("ratio",'640x960');}
                  }
                  if (formdata) {
  
                      jQuery.ajax({
                          url: siteUrl+'design/imgupload',
                          type: "POST",
                          data: formdata,
                          processData: false,
                          contentType: false,
                          success: function (res) {
                            var result = res.search( 'success`' );
                            if(result == '-1')
                            {
                              jQuery('div#response').html('&lt;span style="color:red;"&gt;'+res+'&lt;/span&gt;');
  
                            }else{
  
                              var updatedimg = res.replace("success`", "");
                              var imagesrc = baseUrl+'apps/'+appid+'/'+$('#device_name').text()+'/'+updatedimg; 
                              if (document.getElementById('bg_img')) {
                                  //$('#bg_img').attr('src', imagesrc);
                                  $('#bg_img').attr('style', 'background-image:url("'+imagesrc+'")');
                               } else {
                                  $("#maindialerdesignbg").append("&lt;a href='#' id='bg_img_ank'&gt;&lt;img id='bg_img' style='width:100%' src="+imagesrc+"&gt;&lt;/a&gt;");
                                }
                              jQuery('div#response').html('');
                            }
                            file = '';
                          }
                      });
                  }
              }
              else
              {
                  alert('Not a vaild image!');
              }
          }
      }, false);
    }  
  }); 
  </code></pre>
  
  <p>And My php function as foliows:</p>
  
  <pre><code>public function imgupload() {
  
          $error = '';
  
          $image_info = getimagesize($_FILES['image']['tmp_name']);
  
          if(count($image_info)&gt;0)
          {
              $img_width = $image_info[0];
              $img_height = $image_info[1];
          }
          $device['deviceid'] =$this-&gt;input-&gt;post('deviceid');
          $device['parentid'] =  $this-&gt;input-&gt;post('selected_parentid');
          $parent=$this-&gt;Application_model-&gt;device_parentname($device);               
          $parent_name = $parent[0]['device_properties_name'];
          $parent_folder = preg_replace('/\s+/','',$parent_name);
          if(isset($_POST['icontype']))
          {
              $activeicons = 'activeicons';
              if(isset($_POST['activeicon']))
              { 
                  $parent_folder .= '/'.preg_replace('/\s+/','','Bottom Menu Icons');
                  $parent_folder .= '/'.$activeicons;                
              }else{
                  $parent_folder .= '/'.preg_replace('/\s+/','','Bottom Menu Icons'); 
              }
          }
  
       if($this-&gt;input-&gt;post('ratio'))
       {
        $imgsize = explode("x",$this-&gt;input-&gt;post('ratio'));
        $width = $imgsize[0];
        $height = $imgsize[1];
        if(($width != $img_width) &amp;&amp; ($height != $img_height))
        {
          $error = array('error' =&gt; '&lt;span&gt;image ratio must be '.$this-&gt;input-&gt;post('ratio').'&lt;/span&gt;');
          echo $error['error'];exit;
        }
       }else{
          $error = array('error' =&gt; '&lt;span&gt;image ratio not found.&lt;/span&gt;');
          echo $error['error'];exit; 
       }
       if($this-&gt;input-&gt;post('deviceid') == '1')
        $devicetype = 'Android';
       if($this-&gt;input-&gt;post('deviceid') == '2')
        $devicetype = 'Iphone';
        $config['upload_path'] = './apps/'.$this-&gt;input-&gt;post('appid').'/'.$devicetype.'/'. $parent_folder;
                     if (!is_dir($config['upload_path'])) {
                          mkdir($config['upload_path'], 0777, true);
                          $myFile = $config['upload_path']."/index.html"; // or .php   
                          $fh = fopen($myFile, 'w'); // or die("error");  
                          $stringData = "&lt;html&gt;&lt;head&gt;&lt;title&gt;403 Forbidden&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Directory access is forbidden.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;";   
                          fwrite($fh, $stringData);
                         }
  
       $newFileName = $_FILES['image']['name'];
       $fileExt = array_pop(explode(".", $newFileName));
       $filename = md5(time()).".".$fileExt;
      //set filename in config for upload
       $config['file_name'] = $filename;
       $config['allowed_types'] = 'gif|jpg|png|jpeg';
       $config['max_width']  = $width;
       $config['max_height']  = $height;
       $config['overwrite'] = TRUE;
  
       $this-&gt;load-&gt;library('upload', $config);
       $this-&gt;upload-&gt;initialize($config);
       if ( ! $this-&gt;upload-&gt;do_upload('image'))
       {
        $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors('&lt;span&gt;','&lt;/span&gt;'));
        echo $error['error'];
       }
       else
       {
  
        $_POST['bg_image'] = $parent_folder.'/'.$filename;//$data['upload_data']['file_name'];
        $devappid = $this-&gt;Application_model-&gt;getUserAllApps($this-&gt;input-&gt;post('appid'));
        $_POST['app_details_id'] = $devappid[0]['app_details_id'];
        $this-&gt;Application_model-&gt;saveImageProperties($_POST);
        echo 'success`'.$parent_folder.'/'.$filename;//$data['upload_data']['file_name'];
       }
  
  }
  </code></pre>