title: upload file through ajax
body: <p>I use 2 file index.js, upload.php try to upload file(img) through ajax and if success append to div <code>uploadfile_show</code>.<br>
  but it doesn't work , have few question and below is my code any suggestion?  </p>
  
  <p>Thanks.</p>
  
  <p>upload.php<br>
  1. <code>form enctype</code> still need to add?<br>
  2. <code>if($_FILES)</code> and check $_FILES size or tmp_name still use <code>$_FILES</code>?</p>
  
  <pre><code>if($_FILES){
      $filename = $_FILES['uploadfile']['name'];
      $filetmp = $_FILES['uploadfile']['tmp_name'];
      $filesize = $_FILES['uploadfile']['size'];
      if($filesize &lt; 1000000){
          move_uploaded_file($filetmp,'upload/tmp/'.$filename);
          print"
              upload success
              &lt;img src=\"upload/tmp/$filename\"&gt;
          ";
      }
      else{
      }
  }
  else{
      print"
          &lt;div class=\"uploaddiv\"&gt;
              &lt;form enctype=\"multipart/form_data\"&gt;
                  &lt;input type=\"type\" name=\"uploadfile\"&gt;
                  &lt;input type=\"submit\" value=\"upload\" class=\"btn\"&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      ";
  }
  print"
      &lt;div class=\"uploadfile_show\"&gt;&lt;/div&gt;
  ";
  </code></pre>
  
  <p>index.js<br>
  3. this few line is it the right?<br>
  <code>var uf = $('.uploaddiv form');var fd = new FormData(uf);fd.append('uploadfile', uploadfile);</code><br>
  <code>data: fd,</code><br>
  4. any thing I missed or wrong?</p>
  
  <pre><code>$('.btn').click(function(){
      var uf = $('.uploaddiv form');
      var fd = new FormData(uf);
      fd.append('uploadfile', uploadfile);
      $.ajax({
          type: "POST",
          url: "upload.php",
          data: fd,
          processData:false,
          contentType: false,
          success: function(html){
              $('.uploadfile_show').append(html);
          }
      });
  });
  </code></pre>