Save the index.html and upload.php files to a sibling directory that supports PHP's space, and the test runs
AJAX Client page code: index.html
<div ID =result></div>
<pre class=js name= "code" ><script language=javascript>
//upload function
function Btn_send.onclick () {
data = "
Spliter ="-------7d8d733180846 "
Datadata = data + Spliter +" RN " br> datadata = data + "CONTENT-DISPOSITION:FORM-DATA; Name= "Photofile"; Filename= "C:a.txt" RN
//datadata = data + "Content-type:image/pjpeg" + vbCrLf
Datadata = Data + "Content-type: Text/plain "+" RN "+" rn "
Text =" My name is Wilson Lin. "
Postlength = text.length + data.length + 2 + spliter.length + 4
Package = data + text + "RN" + spliter + "--rn"
Alert (Package)
//Send an XML document to the Web server
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
Xmlhttp.open ("POST", "./upload.PHP ", false);
Xmlhttp.setrequestheader ("Content-type", "multipart/form-data;") boundary=-----7d8d733180846 ");
Xmlhttp.setrequestheader ("Content-length", postlength);
Xmlhttp.send (package);
//Displays information returned by the server
Result.innerhtml=xmlhttp. ResponseText;
}
</SCRIPT>
</PRE>
</body>
|
PHP Server-side code: upload.php
<?php
$_files[' Photofile ']: is an array of uploaded images
$uploadfile: Store Address
$uploadfile = "d:/" $_files[' photofile ' [' name '];
Copy ($_files[' photofile '] [' tmp_name '], $uploadfile);
echo "URL: <a href= ' http://localhost/". $_files[' photofile ' [' name ']. ' target= ' _blank ' > '. $_files[' Photofile ' [' name ']. " </a><br/> ";
?>
Upload successed! |