Rumah > Artikel > pembangunan bahagian belakang > php关于file表单与ajax无刷新的有关问题
php关于file表单与ajax无刷新的问题
upload1.php代码如下
<br /><script type="text/javascript"><br />function checkfile(name){<br /> var xhr;<br /> if(window.XMLHttpRequest){<br /> xhr = new XMLHttpRequest();<br /> }<br /> else xhr = new ActiveXObject("Microsoft.XMLHTTP");<br /><br /> xhr.onreadystatechange=function(){<br /> if(xhr.readyState == "4" && xhr.status == "200"){<br /> document.getElementById("err").innerHTML = xhr.responseText;<br /> }<br /> }<br /><br /> xhr.open("POST","result.php",true);<br /> xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");<br /> xhr.send("name=" + name);<br />}<br /></script><br /><form enctype="multipart/form-data" method="post" action="upload2.php"><br /> <input type="hidden" name="MAX_FILE_SIZE" value="10000" /><br /> 上传文件:<input type="file" name="filename" onchange="checkfile(this.value)" /><br /><br /> <input type="submit" value="上传" /><br /><br /> <br /> <p id="err"></p><br /></form><br />
<br /><?php<br /><br /> $filepath = $_POST["name"]; <br /> $err = "";<br /> if(filesize($filepath) > 10000) $err = "文件不得超过10kb!";<br /> <br /> echo $err;<br /><br />?><br />