相思资源网 Design By www.200059.com
AJAX 客户端页面代码: index.html
复制代码 代码如下:
<html>
<body>
<h1>Ajax file upload sample</h1><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"
datadata = data + spliter + "\r\n"
datadata = data + "Content-Disposition: form-data; name=\"photofile\"; filename=\"C:\\a.txt\"\r\n"
// datadata = data + "Content-Type: image/pjpeg" + vbCrLf
datadata = data + "Content-Type: text/plain" + "\r\n" + "\r\n"
text = "My name is Wilson Lin."
postLength = text.length + data.length + 2 + spliter.length + 4
package = data + text + "\r\n" + spliter + "--\r\n"

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>

PHP服务器端代码: upload.php
复制代码 代码如下:
<?php
// $_FILES['photofile']:是获得上传图片的数组
// $uploadfile:存放地址
$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!
标签:
ajax,无刷新,上传图片

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“php ajax无刷新上传图片实例代码”

暂无php ajax无刷新上传图片实例代码的评论...