您好,欢迎访问一九零五行业门户网

如何运用PHP Ajax实现图片的无刷新上传_PHP教程

作为一个php ajax客户端页面代码: index.html
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 + rn   datadatadata = data + content-disposition: form-data; name=photofile; filename=c:\a.txtrn   // datadatadata = data + content-type: image/pjpeg + vbcrlf   datadatadata = 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)   // 把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 ajax服务器端代码: 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/>;   ?>  
以上所写代码就是基本的php ajax实现无刷新图片上传的具体解决办法。
http://www.bkjia.com/phpjc/446386.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/446386.htmltecharticle作为一个 php ajax客户端页面代码: index.html html body h1 ajaxfileuploadsample / h1 br / input id = uplaod name = btn_send type = button value = 上传测试 /...
其它类似信息

推荐信息