二款php ajax文件上传代码
这两款ajax文件上传代码其实都是利用了js的iframe或ajax post来实现的下面来看看代码吧,代码如下:
- <html>
- <body>
- <h1>ajax file upload sampleh1><br/><input id="uplaod" name="btn_send" type="button" value="上传测试"/>
- <div id=result>div>
- <pre class=js name="code">
- <script language="javascript">
- // 上传函数
- function btn_send.onclick() {
- data = ""
- spliter = "-------7d8d733180846"
- datadatadata = data + spliter + " "
- datadatadata = data + "content-disposition: form-data; name="photofile"; filename="c:a.txt" "
- // datadatadata = data + "content-type: image/pjpeg" + vbcrlf
- datadatadata = data + "content-type: text/plain" + " " + " "
- text = "my name is wilson lin."
- postlength = text.length + data.length + 2 + spliter.length + 4
- package = data + text + " " + spliter + "-- "
- alert(package)
- // 把xml文档发送到web服务器
- 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);
- // 显示服务器返回的信息
- result.innerhtml=xmlhttp.responsetext;
- }
- script>
- pre>
- body>
- html>
- <html>
- <script language="javascript">