title: javascript ajax upload system check condition
body: <p>I was following a tutorial about how to make an javascript/ajax upload system with progress (%) indicator . I have successfully added a css progress bar indicator to it . 
  But i have a problem that i can't solve is how to put to condition of upload like: type, file size, file is set, ....
  here is my code (upload.php)</p>
  
  <pre><code>&lt;?php
  foreach($_FILES['file']['name'] as $key =&gt; $name){
          if ($_FILES['file']['error'][$key] == 0 &amp;&amp; move_uploaded_file($_FILES['file']['tmp_name'][$key], "files/{$name}")){
              $uploaded[] = $name;
          }
      }
      if(!empty($_POST['ajax'])){
          die(json_encode($uploaded));
      }
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
      &lt;script type="text/javascript" src="upload.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
          &lt;div id="uploaded"&gt;
              &lt;?php
  
              if (!empty($uploaded)){
                  foreach ($uploaded as $name){
                      echo '&lt;div&gt;&lt;a href="files/',$name,'"&gt;',$name,'&lt;/a&gt;&lt;/div&gt;';
                  }
              }
  
              ?&gt;
               &lt;/div&gt;
  &lt;div id="upload_progress"&gt;&lt;/div&gt;
          &lt;div&gt;
              &lt;form action="" method="post" enctype="multipart/form-data"&gt;
  &lt;input type="file" id="file" name="file[]" /&gt;
  &lt;input type="submit" id="submit" value="upload" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p></p>
  
  <p>and this is the javascript file (upload.js):</p>
  
  <pre><code>var handleUpload = function(event){
      event.preventDefault();
      event.stopPropagation();
  
      var fileInput = document.getElementById('file');
  
      var data = new FormData();
  
      data.append('ajax', true);
      for (var i = 0; i &lt; fileInput.files.length; ++i){
          data.append('file[]', fileInput.files[i]);
      }   
  
      var request = new XMLHttpRequest();
  
      request.upload.addEventListener('progress', function(event){
          if(event.lengthComputable){
              var percent = event.loaded / event.total;
              var progress = document.getElementById('upload_progress');
  
              while (progress.hasChildNodes()){
                  progress.removeChild(progress.firstChild);
              }
              progress.appendChild(document.createTextNode(Math.round(percent * 100) +' %'));
              document.getElementById("loading-progress-17").style.width= Math.round(percent * 100) +'%';
          }
      });
      request.upload.addEventListener('load', function(event){
          document.getElementById('upload_progress').style.display = 'none';
      });
      request.upload.addEventListener('error', function(event){
          alert('Upload failed');
      });
      request.addEventListener('readystatechange', function(event){
          if (this.readyState == 4){
              if(this.status == 200){
                  var links = document.getElementById('uploaded');
                  var uploaded = eval(this.response);
                  var div, a;
                  for (var i = 0; i &lt; uploaded.length; ++i){
                      div = document.createElement('div');
                      a = document.createElement('a');
                      a.setAttribute('href', 'files/' + uploaded[i]);
                      a.appendChild(document.createTextNode(uploaded[i]));
                      div.appendChild(a);
                      links.appendChild(div);
                  }
              }else{
                  console.log('server replied with HTTP status ' + this.status);
              }
          }
      });
      request.open('POST', 'upload.php');
      request.setRequestHeader('Cache-Control', 'no-cache');
      document.getElementById('upload_progress').style.display = 'block';
      request.send(data);
  
  }
  
  window.addEventListener('load', function(event){
  
      var submit = document.getElementById('submit');
      submit.addEventListener('click', handleUpload);
  });
  </code></pre>
  
  <p>I just need and example of how to check file size is less than 50MB and i can do the other checks my self i just don't know how to check condition in this upload system.
  Thanks in advance</p>