Home>
<?php
if (isset ($_ post ["upload"])) {
  var_dump ($_ files);
  move_uploaded_file ($_ files ["upfile"] ["tmp_name"], "up_tmp /". time (). ". dat");
  //header ("location:test.php");
  exit;
}
?>
<! Doctype html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <title>html5 ajax uploader</title>
  <script src="jquery-2.1.1.min.js"></script>
</head>
<body>
<p><input type="file"></p>
<p><input type="button" value="upload with native js"></p>
<p><input type="button" value="upload with jquery"></p>
<script>
  /* Native JS version * /
  document.getelementbyid ("upjs"). onclick=function () {
    /* formdata is the form data class * /
    var fd=new formdata ();
    var ajax=new xmlhttprequest ();
    fd.append ("upload", 1);
    /* Add files to the form * /
    fd.append ("upfile", document.getelementbyid ("upfile"). files [0]);
    ajax.open ("post", "test.php", true);
    ajax.onload=function () {
      console.log (ajax.responsetext);
    };
    ajax.send (fd);
  }
  /* jquery version * /
  $("#upjquery"). on ("click", function () {
    var fd=new formdata ();
    fd.append ("upload", 1);
    fd.append ("upfile", $("#upfile"). get (0) .files [0]);
    $.ajax ({
      url:"test.php",      type:"post",      processdata:false,      contenttype:false,      data:fd,      success:function (d) {
        console.log (d);
      }
    });
  });
</script>
</body>
</html>
php
  • Previous Forty-eighth of Manipulating Data in ASPNET 20: Using Open Concurrency for the SqlDataSource Control
  • Next The composition and creation of derived classes in C ++ programming