ajax无刷新上传图片实例_Ajax编程_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

ajax无刷新上传图片实例

作者:黑客防线网安Ajax教程基地 来源:黑客防线网安Ajax教程基地 浏览次数:0

本篇关键词:实例图片上传刷新
黑客防线网安网讯:将index.html和upload.php文件保存到apache工作目录,例子使用安装目录D:/Program Files/Apache Software Foundation/Apache2.2/htdocs/AJAX 客户端页面代码: index.html<html>  <body>  <...

将index.html和upload.php文件保存到apache工作目录例子使用安装目录D:/Program Files/Apache Software Foundation/Apache2.2/htdocs/

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 + " "  
 datadata = data + "Content-Disposition: form-data; name="photofile"; filename="C:\a.txt" "  
 // datadata = data + "Content-Type: image/pjpeg" + vbCrLf  
 datadata = 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>

PHP服务器端代码: upload.php

<?php 
// $_FILES['photofile']:是获得上传图片的数组  
// $uploadfile:存放地址  
$uploadfile = "D:/Program Files/Apache Software Foundation/Apache2.2/htdocs/".$_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! 

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-15612-1.html
网站维护教程更新时间:2012-04-05 00:04:25  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer