title: Uploading files using PHP `$_FILES` is not set?
body: <p>So I've been developing a plugin for WordPress.<br>
  As I already have made an application which uploads files for me, I thought it would be easy but alas, I can't think of what I am doing wrong.</p>
  
  <p>The problem is; my <code>$_FILES['image']</code> is not set. </p>
  
  <p>Can anyone tell me what is wrong with my code, because I can't find out what it is.<br></p>
  
  <p><strong>Form</strong></p>
  
  <pre><code>&lt;form action="" method="POST" enctype="multipart/form-data"&gt;
              &lt;table class="table ws-form-table"&gt;
                  &lt;tbody&gt;
                      &lt;tr&gt;
                          &lt;td&gt;
                              Add Text:
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;input type="text" id="ws-text"&gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;button type="button" class="btn btn-primary ws-add-text ws-add-button"&gt;+&lt;/button&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td&gt;
                              Add Image:
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;input type="file" name="image"&gt;&lt;progress&gt;&lt;/progress&gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;button type="button" class="btn btn-primary ws-add-image ws-add-button"&gt;+&lt;/button&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/tbody&gt;
              &lt;/table&gt;
              &lt;div class="preview-container"&gt;
                  &lt;div class="preview-strict"&gt;
                      &lt;img class="ws-image" src="&lt;?php echo $feat_image; ?&gt;" alt="" style="width: 300px; height: 300px;"&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>jQuery('.ws-add-image').click(function() {
      var formData = new FormData(jQuery('form')[0]);
      console.log('Click Initiated');
      console.log('Ajax Try...');
      jQuery.ajax({
  
          url: '../../wp-content/plugins/my-plugin/my-plugin-handler.php',
          type: 'POST',
          xhr: function() {
              var myXhr = jQuery.ajaxSettings.xhr();
              if(myXhr.upload){ 
                  myXhr.upload.addEventListener('progress',progressHandlingFunction, false);
              }
              return myXhr;
          },
  
          data: formData,
  
          cache: false,
          contentType: false,
          processData: false,
          error: function() {
              console.log('Error Initiated');
          },
      }).done(function() {
          alert('dsa');
          jQuery('.preview-strict').prepend('&lt;div id="dragHelper" style="display:inline-block; z-index: 999; cursor: move;"&gt;&lt;img id="theImg" src="../../wp-content/plugins/my-plugin/images/' + readCookie('image') + '" width="200px" height=200px; /&gt;&lt;/div&gt;');
          jQuery("#dragHelper").draggable({drag: function(){
              var offset = jQuery(this).offset();
              var xPos = offset.left;
              var yPos = offset.top;
              jQuery('#posX').text('x: ' + xPos);
              jQuery('#posY').text('y: ' + yPos);
          }
          });
  
          jQuery("#theImg").resizable();
  
      });
      alert(readCookie('image'));
      console.log('Done!');
  });
  function progressHandlingFunction(e){
      if(e.lengthComputable){
          jQuery('progress').attr({value:e.loaded,max:e.total});
      }
  }
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>&lt;?php 
  ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  error_reporting(E_ALL);
  include_once($_SERVER['DOCUMENT_ROOT'].'/test/wp-load.php' );
  global $wpdb;
  $table_name = $wpdb-&gt;prefix . "my-plugin"; 
  
  if(isset($_FILES['image'])) {
      $wty = 'ISSET';
        $sql = $wpdb-&gt;get_results("SELECT ID FROM " . $table_name . " ORDER BY ID DESC LIMIT 1");
        echo $_FILES['image']['name'];
        foreach( $wpdb-&gt;get_results("SELECT ID FROM " . $table_name . " ORDER BY ID DESC LIMIT 1") as $key =&gt; $row) {
            $id = $row-&gt;ID;
        }
  
        $temp = explode(".", $_FILES["image"]["name"]);
        $last = $id . round(microtime(true)) . '.' . end($temp);
        $errors= array();
        $file_name = $_FILES['image']['name'];
        $file_size = $_FILES['image']['size'];
        $file_tmp = $_FILES['image']['tmp_name'];
        $file_type = $_FILES['image']['type'];
        $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
  
        $ext = end((explode(".", $file_name)));
  
        $expensions= array("jpeg","jpg","png");
  
        if(empty($errors)==true) {
  
           move_uploaded_file($file_tmp, ABSPATH . "test/wp-content/plugins/my-plugin/images/" . $last);
  
        }
  
        else
  
        {
  
           print_r($errors);
  
        }
  }
  
  
  $cookie_name = "image";
  $cookie_value = $wty;
  $cookie_exp = time() + (86400 * 30);
  
  
  
  setcookie($cookie_name, $cookie_value, $cookie_exp, "/");
  
  
  ?&gt;
  </code></pre>
  
  <p>So this is how it works: Image gets chosen, button gets clicked, click event runs, ajax runs a PHP file. The PHP file (needs to) upload image, creates cookie with image name. Image name gets pulled from cookie, and adds it to the DOM after ajax done.</p>
  
  <p>I've tried to look this up but for some reason I can't find anything but peoples saying that I might be forgetting <code>enctype="multipart/form-data"</code>.</p>
  
  <p>So what am I doing wrong? <br></p>
  
  <p>Keep in mind that this is a WordPress plugin. So it may be something WordPress related. But I don't think so.</p>
  
  <p>I'm still learning so any help with improving the code is appreciated!</p>