title: Passing an image file is unsuccessful using AJAX
body: <p>I am facing an error where I am unable to pass the image file through AJAX when uploading a image file. Here are my codes</p>
  <p>AJAX</p>
  <pre><code>    var file = $(&quot;#thumbnail&quot;).get(0).files[0];
  alert(file.name+&quot; | &quot;+file.size+&quot; | &quot;+file.type);
  var formdata = new FormData();
  formdata.append(&quot;file&quot;, file);
  
  alert (formdata);
  
      $.ajax({
          url: &quot;php/post-check.php&quot;,
          type: &quot;POST&quot;,
          data: {
              title: title,
              thumbnail: formdata
          },
          success: function (data) {
              $(&quot;div#postresult&quot;).removeClass(&quot;alert alert-danger&quot;);
              $(&quot;div#postresult&quot;).html(data);
          }
      });
  </code></pre>
  <p>PHP</p>
  <pre><code>&lt;?php 
          $target_dir = &quot;../thumbnail-pictures/&quot;;
          $target_file = $target_dir . basename($_FILES[&quot;thumbnail&quot;][&quot;name&quot;]);
          $uploadOk = 1;
          $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  
          if (file_exists($target_file)) {
              echo &quot;Sorry, thumbnail file already exists. &lt;br&gt;&quot;;
              $uploadOk = 0;
          }
  
          if ($_FILES[&quot;thumbnail&quot;][&quot;size&quot;] &gt; 1000000) {
              echo &quot;Sorry, your file is too large.&quot;;
              $uploadOk = 0;
          }
  
          if($imageFileType != &quot;jpg&quot; &amp;&amp; $imageFileType != &quot;png&quot; &amp;&amp; $imageFileType != &quot;jpeg&quot;) {
              echo &quot;Sorry, only JPG, JPEG, PNG &amp; GIF files are allowed.&quot;;
              $uploadOk = 0;
          }
  
          if ($uploadOk == 0) {
              echo &quot;Sorry, your file was not uploaded, &quot;;
  
          } else {
              if (move_uploaded_file($_FILES[&quot;thumbnail&quot;][&quot;tmp_name&quot;], $target_file)) {
                  
              } else {
                  echo &quot;Sorry, there was an error uploading your file.&quot;;
              }
          }
          ?&gt;
  </code></pre>
  <p>HTML</p>
  <pre><code>&lt;form action=&quot;&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; id=&quot;newpost&quot;&gt;
                  &lt;div class=&quot;col-lg-12&quot;&gt;
                          &lt;div class=&quot;form-group&quot;&gt;
                              &lt;label&gt;Title&lt;/label&gt;
                              &lt;input class=&quot;form-control&quot; name=&quot;title&quot; id=&quot;title&quot; required&gt;
                              
                          &lt;/div&gt;
  
                          &lt;div class=&quot;form-group&quot;&gt;
                              &lt;label&gt;Video Thumbnail **Only JPEG &amp; PNG is accepted**&lt;/label&gt;
                              &lt;input type=&quot;file&quot; name=&quot;thumbnail&quot; id=&quot;thumbnail&quot; accept=&quot;image/png, image/gif, image/jpeg&quot; &gt;
                          &lt;/div&gt;
  </code></pre>
  <p>The PHP code itself is working fine so I assume that the problem lies within the AJAX section, however I am unsure of how to solve this. Thankful for any help given!</p>