How to use PHP Ajax to implement the image without refreshing upload _php tutorial

Source: Internet
Author: User
As aPHP AJAX Client page code: index.html

 
 
  1. < HTML >
  2. < Body >
  3. < h1 > Ajax File Upload sample h1 > < br /> < Span class= "Tag-name" >input id = Span class= "Attribute-value" > "uplaod" name = "btn_send" type = "button" value = "upload test" />
  4. < div id = result > !-- div >
  5. < PRE class= js name="code"> <SCRIPT LANGUAGE=JavaScript >
  6. Upload function
  7. function Btn_send.onclick () {
  8. Data = ""
  9. Spliter = "-------7d8d733180846"
  10. Data Datadata = data + Spliter + "RN"
  11. Data Datadata = data + "CONTENT-DISPOSITION:FORM-DATA; name = "Photofile"; filename = "C:\a.txt" rn "
  12. // Data Datadata = data + "Content-type:image/pjpeg" + vbCrLf
  13. Data Datadata = data + "Content-type:text/plain" + "RN" + "RN "
  14. text = "My name is Wilson Lin."
  15. Postlength = text . length + data.length + 2 + spliter.length + 4
  16. Package = Data + text + "RN" + spliter + "--rn"
  17. Alert (Package)
  18. Sending an XML document to the Web server
  19. var XMLHTTP = New ActiveXObject ("Microsoft.XMLHTTP");
  20. Xmlhttp.open ("POST", "./upload.php", false);
  21. Xmlhttp.setrequestheader ("Content-type", "Multipart/form-data; Boundary =-----7d8d733180846 ");
  22. Xmlhttp.setrequestheader ("Content-length", postlength);
  23. Xmlhttp.send (package);
  24. Display information returned by the server
  25. result.innerhtml = XMLHTTP . ResponseText;
  26. }
  27. SCRIPT >
  28. PRE >
  29. Body >
  30. html>

PHP Ajax server-side code: upload.php

 
 
  1. Php
  2. $_files[' Photofile ': is an array of images to get uploaded
  3. $uploadfile: Store Address
  4. $ UploadFile = "d:/" . $_files[' photofile ' [' name '];
  5. Copy ($_files[' photofile ' [' tmp_name '], $uploadfile);
  6. echo "URL: <a href= ' http://localhost/'. $_files[' photofile ' [' Name']. "' target=' _blank '>'. $_files[' photofile ' [' Name ']. " a><br/> ";
  7. ?>

The above code is the basic PHP AJAX implementation of non-refresh image upload specific solutions.


http://www.bkjia.com/PHPjc/446386.html www.bkjia.com true http://www.bkjia.com/PHPjc/446386.html techarticle as a PHP AJAX client page code: index.html HTML body h1 ajaxfileuploadsample/h1 br/input id = "UPLAOD" name = "Btn_send" Typ E = "button" value = "upload Test"/...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.