二款php ajax檔案上傳代碼(1/4)

來源:互聯網
上載者:User
 代碼如下 複製代碼

<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=網頁特效>
// 上傳函數
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>


<html>
<script language="javascript">
<!--
   var xmlhttp;
  function createxmlhttprequest() {
   if (window.activexobject) {
    xmlhttp = new activexobject("microsoft.xmlhttp");
   }
   else if (window.xmlhttprequest) {
    xmlhttp = new xmlhttprequest();
   }
  }
  function uploade(e){
   var fileadd
   fileadd = e;
   
    createxmlhttprequest();
    xmlhttp.onreadystatechange = handlestatechange;
    var url = "pic_upload.asp教程?add="+fileadd+"&timestamp="+new date().gettime();
    xmlhttp.open("get",url,true);
    xmlhttp.send(null);
  
  }
  function handlestatechange() {
   document.getelementbyid("content").innerhtml = "這裡寫進度條";
   if (xmlhttp.readystate == 4) {
    if (xmlhttp.status == 200) {
     
     document.getelementbyid("content").innerhtml = xmlhttp.responsetext;
     
    }
    else{
     //alert(xmlhttp.status);
                                                                                  alert('錯誤,請聯絡管理員!');
     
    }
   }
  }
//-->
</script>
 <body>
<input type=file name="mefile" id="fileadd" onchange="alert(document.getelementbyid('fileadd').value);">
<input type="submit" value="上傳" onclick="uploade(document.getelementbyid('fileadd').value);">
<div id="content"></div>
 </body>
</html>

 

首頁 1 2 3 4 末頁
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.