As aPHP AJAX Client page code: index.html
- < HTML >
- < Body >
- < h1 > Ajax File Upload sample h1 > < br /> < Span class= "Tag-name" >input id = Span class= "Attribute-value" > "uplaod" name = "btn_send" type = "button" value = "upload test" />
- < div id = result > !-- div >
- < PRE class= js name="code"> <SCRIPT LANGUAGE=JavaScript >
- Upload function
- function Btn_send.onclick () {
- Data = ""
- Spliter = "-------7d8d733180846"
- Data Datadata = data + Spliter + "RN"
- Data Datadata = data + "CONTENT-DISPOSITION:FORM-DATA; name = "Photofile"; filename = "C:\a.txt" rn "
- // Data Datadata = data + "Content-type:image/pjpeg" + vbCrLf
- Data 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)
- Sending 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);
- Display information returned by the server
- result.innerhtml = XMLHTTP . ResponseText;
- }
- SCRIPT >
- PRE >
- Body >
- html>
PHP Ajax server-side code: upload.php
- Php
- $_files[' Photofile ': is an array of images to get uploaded
- $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/> ";
- ?>
The above code is the basic PHP AJAX implementation of non-refresh image upload specific solutions.
http://www.bkjia.com/PHPjc/446386.html www.bkjia.com true http://www.bkjia.com/PHPjc/446386.html techarticle as a PHP AJAX client page code: index.html HTML body h1 ajaxfileuploadsample/h1 br/input id = "UPLAOD" name = "Btn_send" Typ E = "button" value = "upload Test"/...