作为一个PHP Ajax客户端页面代码: index.html
<ol class="dp-xml"> <li class="alt"><span><strong><font color="#006699"><span class="tag"><span class="tag-name">html</span><span class="tag">></span></span></font></strong><span> </span></span></li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">body</span><span class="tag">></span></span></font></strong><span> </span> </li> <li class="alt"> <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">h1</span><span class="tag">></span></span></font></strong><span>Ajax file upload sample</span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">h1</span><span class="tag">></span><span class="tag"><span class="tag-name">br</span><span class="tag">/></span><span class="tag"><span class="tag-name">input</span></span></span></font></strong><span> </span><span class="attribute"><font color="#ff0000">id</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"uplaod"</font></span><span> </span><span class="attribute"><font color="#ff0000">name</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"btn_send"</font></span><span> </span><span class="attribute"><font color="#ff0000">type</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"button"</font></span><span> </span><span class="attribute"><font color="#ff0000">value</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"上传测试"</font></span><span class="tag"><strong><font color="#006699">/></font></strong></span><span> </span> </li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">div</span></span></font></strong><span> </span><span class="attribute"><font color="#ff0000">id</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">result</font></span><strong><font color="#006699"><span class="tag">></span><span class="tag"></span><span class="tag-name">div</span><span class="tag">></span></font></strong><span> </span> </li> <li class="alt"> <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">PRE</span></span></font></strong><span> </span><span class="attribute"><font color="#ff0000">class</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">js</font></span><span> </span><span class="attribute"><font color="#ff0000">name</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"code"</font></span><strong><font color="#006699"><span class="tag">></span><span class="tag"><span class="tag-name">SCRIPT</span></span></font></strong><span> </span><span class="attribute"><font color="#ff0000">LANGUAGE</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">JavaScript</font></span><span class="tag"><strong><font color="#006699">></font></strong></span><span> </span> </li> <li class=""><span>// 上传函数 </span></li> <li class="alt"><span>function btn_send.onclick() { </span></li> <li class=""> <span></span><span class="attribute"><font color="#ff0000">data</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">""</font></span><span> </span> </li> <li class="alt"> <span></span><span class="attribute"><font color="#ff0000">spliter</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">"-------7d8d733180846"</font></span><span> </span> </li> <li class=""> <span></span><span class="attribute-value"><font color="#0000ff">data</font></span><span class="attribute"><font color="#ff0000">datadata</font></span><span> = data + spliter + "rn" </span> </li> <li class="alt"> <span></span><span class="attribute-value"><font color="#0000ff">data</font></span><span class="attribute"><font color="#ff0000">datadata</font></span><span> = data + "Content-Disposition: form-data; </span><span class="attribute"><font color="#ff0000">name</font></span><span>="photofile"; </span><span class="attribute"><font color="#ff0000">filename</font></span><span>="C:\a.txt"rn" </span> </li> <li class=""> <span>// </span><span class="attribute-value"><font color="#0000ff">data</font></span><span class="attribute"><font color="#ff0000">datadata</font></span><span> = data + "Content-Type: image/pjpeg" + vbCrLf </span> </li> <li class="alt"> <span></span><span class="attribute-value"><font color="#0000ff">data</font></span><span class="attribute"><font color="#ff0000">datadata</font></span><span> = data + "Content-Type: text/plain" + "rn" + "rn" </span> </li> <li class=""> <span></span><span class="attribute"><font color="#ff0000">text</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">"My name is Wilson Lin."</font></span><span> </span> </li> <li class="alt"> <span></span><span class="attribute"><font color="#ff0000">postLength</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">text</font></span><span>.length + data.length + 2 + spliter.length + 4 </span> </li> <li class=""> <span></span><span class="attribute"><font color="#ff0000">package</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">data</font></span><span> + text + "rn" + spliter + "--rn" </span> </li> <li class="alt"><span>alert(package) </span></li> <li class=""><span>// 把XML文档发送到Web服务器 </span></li> <li class="alt"> <span>var </span><span class="attribute"><font color="#ff0000">xmlhttp</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">new</font></span><span> ActiveXObject("Microsoft.XMLHTTP"); </span> </li> <li class=""><span>xmlhttp.open("POST","./upload.php",false); </span></li> <li class="alt"> <span>xmlhttp.setRequestHeader("Content-Type", "multipart/form-data; </span><span class="attribute"><font color="#ff0000">boundary</font></span><span>=-----7d8d733180846"); </span> </li> <li class=""><span>xmlhttp.setRequestHeader("Content-Length", postLength); </span></li> <li class="alt"><span>xmlhttp.send(package); </span></li> <li class=""><span>// 显示服务器返回的信息 </span></li> <li class="alt"> <span></span><span class="attribute"><font color="#ff0000">result.innerHTML</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">xmlhttp</font></span><span>.ResponseText; </span> </li> <li class=""><span>} </span></li> <li class="alt"> <span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">SCRIPT</span><span class="tag">></span></font></strong><span> </span> </li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">PRE</span><span class="tag">></span></font></strong><span> </span> </li> <li class="alt"> <span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">body</span><span class="tag">></span></font></strong><span> </span> </li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">html</span><span class="tag">></span></font></strong><span> </span> </li> </ol>
PHP Ajax服务器端代码: upload.php
<ol class="dp-xml"> <li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span></span></li> <li class=""><span>// $_FILES['photofile']:是获得上传图片的数组 </span></li> <li class="alt"><span>// $uploadfile:存放地址 </span></li> <li class=""> <span>$</span><span class="attribute"><font color="#ff0000">uploadfile</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">"D:/"</font></span><span>.$_FILES['photofile']['name']; </span> </li> <li class="alt"><span>copy( $_FILES['photofile']['tmp_name'], $uploadfile ); </span></li> <li class=""> <span>echo "URL: </span><strong><font color="#006699"><span class="tag"><span class="tag-name">a</span></span></font></strong><span> </span><span class="attribute"><font color="#ff0000">href</font></span><span>='http://localhost/".$_FILES['photofile']['name</span><span class="attribute-value"><font color="#0000ff">']."'</font></span><span> </span><span class="attribute"><font color="#ff0000">target</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">'_blank'</font></span><span class="tag"><strong><font color="#006699">></font></strong></span><span>".$_FILES['photofile']['name']."</span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">a</span><span class="tag">></span><span class="tag"><span class="tag-name">br</span><span class="tag">/></span></span></font></strong><span>"; </span> </li> <li class="alt"> <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> </ol>
以上所写代码就是基本的PHP Ajax实现无刷新图片上传的具体解决办法。

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

Dreamweaver Mac版
视觉化网页开发工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

记事本++7.3.1
好用且免费的代码编辑器