-----------------------------------form.html---------------------------------------
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8" >
<title>Document</title>
<script type= "Text/javascript" >
function Send () {
var pic = document.getelementsbytagname (' input ') [0].files[0];
var fd = new FormData ();
Fd.append (' pic ', pic);
var xmlhttp = new XMLHttpRequest ();
Xmlhttp.onreadystatechange = function () {
if (this.readystate = = 4 && this.status = = 200) {
document.getElementById (' info '). InnerHTML = This.responsetext;
}
}
Xmlhttp.open (' POST ', ' upload.php ', true);
Xmlhttp.send (FD);
}
</script>
<body>
<div id= "Info" ></div>
<form action= "" >
<input type= "file" onchange= "Send ()"/>
</form>
</body>
--------------------------------------upload.php-------------------------------------
<?php
if (Move_uploaded_file ($_files[' pic '] [' tmp_name '], './upload/'. $_files[' pic ' [' name '])) {
Echo ' upload succeeded ';
}else{
Echo ' upload failed ';
}
?>
This article is from "Stone" blog, please be sure to keep this source http://stoneryan.blog.51cto.com/4534150/1532548