title: XMLHttpRequest Level 2 - Determinate if upload finished
body: <p>I am using ajax for file uploads.
  After the file is uploaded, php should check it (mime, size, virus (clamscan) and more) - this takes some seconds for larger files. While the file is uploading, a HTML5 <code>&lt;progress&gt;</code> is filling, when the file is ready and PHP starts checking, the progress should switch to indeterminate. I thought of to ways to do this (which both do <em>not</em> work):</p>
  
  <p><strong>Checking upload.onload event</strong></p>
  
  <pre><code>xhr.upload.addEventListener("load", function (e) {
      $("#uploadprogress").attr("value", false);
      $("#uploadprogress").attr("max", false);
      $("#progress").text("Checking file...");
  });
  </code></pre>
  
  <p>This doesn't work, because the <code>onload</code>-event firest when the request is ready, not when upload is ready.</p>
  
  <p><strong>Checking if upload progress percentage = 100%</strong></p>
  
  <pre><code>xhr.upload.addEventListener("progress", function (e) {
      if (e.lengthComputable &amp;&amp; e) {
          p = (e.loaded / e.total);
          if (p==1) {
              $("#uploadprogress").attr("value", false);
              $("#uploadprogress").attr("max", false);
              $("#progress").text("Checking file...");
          } else {
              var percent = Math.ceil(p * 1000) / 10;
              $("#uploadprogress").val(e.loaded);
              $("#uploadprogress").attr("max", e.total);
              $("#progress").text("Uploading... " + percent + "%");
          }
     }
  }
  });
  </code></pre>
  
  <p>This does not work, because the upload percentage sometimes stops at approx. 97%, despite the upload is finished and PHP starts handling the files</p>
  
  <p>Is there another possibility checking this?</p>