Home > front end >  Ajax file upload
Ajax file upload

Time:03-15

front-end code:



<meta charset="utf-8" & gt;
Novice tutorial (runoob.com) & lt;/title> <br/><script> <br/>The function myFunction () {<br/>//alert (" enter the function "); <br/>//the document. The getElementById (" shuchu "). The innerHTML="Hello World"; <br/>Var form=document. GetElementById (' form1 '); <br/>Var formdata=https://bbs.csdn.net/topics/new formdata (form); <br/><br/><br/>Var XMLHTTP; <br/>If (window. The XMLHttpRequest) <br/>{<br/>//IE7 +, Firefox, Chrome, Opera, Safari execute code <br/>XMLHTTP=new XMLHttpRequest (); <br/>} <br/>The else <br/>{<br/>//IE6, IE5 browser code execution <br/>XMLHTTP=new ActiveXObject (" Microsoft. XMLHTTP "); <br/>} <br/>XMLHTTP. Onreadystatechange=function () <br/>{<br/>If (XMLHTTP. ReadyState==4 & amp; & XMLHTTP. Status==200) <br/>{<br/>//document. GetElementById (" shuchu "). The innerHTML=XMLHTTP. The responseText; <br/>Alert (XMLHTTP. The responseText); <br/>} <br/>} <br/>XMLHTTP. Open (" POST ", "test_ajax_formdata. PHP", true); <br/>XMLHTTP. Send (formdata); <br/>} <br/></script> <br/><br/></head> <br/><body> <br/><br/><The form name="form1" id="form1" onsubmit="myFunction ()" & gt; <br/>A: & lt; Input type="text" name="firstname" & gt; <br> <br/>B: & lt; Input type="text" name="lastname" & gt; <br> <br/><Input type="file" name="file" & gt; <br/><Input type="submit" value="submit" https://bbs.csdn.net/topics/& gt; <br/></form> <br/><br/><Div id="shuchu" & gt; Ddddddddddddddddd</div> <br/><br/></body> <br/></html> <br/><br/><span style="color: # FF0000;"> the back-end code: </span> <br/><? PHP <br/>Echo "is A value:". $_POST [r]. "firstname", "& lt; Br> "; <br/>Echo "is the value of B:". $_POST [r]. "lastname", "& lt; Br> "; <br/>Echo "upload file name:". $_FILES [" file "] [r]. "the name" "& lt; Br> "; <br/>Echo "file type:". $_FILES [" file "] [" type "] "& lt; Br> "; <br/>Echo "file size:". ($_FILES [" file "] [" size "]/1024). "kB<Br> "; <br/>Echo "file temporary storage location:". $_FILES [" file "] [" tmp_name "]; <br/>?> <br/><br/>Thinking: the whole form data upload PHP output in the form of various value after <br/>Problem a form can be mixed together with formdata upload? Because have general data and file data in this table single mixed with <br/>Problem two backend server is how analytical form? After the data is sent to a PHP service process and parsing algorithms such as data sent to the server on the server is how to distinguish the general data and file data, <br/><br/>Hope to have elder can help the first thank you! What with the recommendation of books can solve my problem, as long as it is can help to solve the problem of information, thank you very much!<p class="article - content rp"> CodePudding user response: </p>Problem a: you can,, <br/>Problem two: PHP are not ripe,, never done, but I use the node have done this thing, the node of the back-end to the corresponding module to parse the FormData form data, the node with multiparty this module, there are some similar can also, PHP I don't know how, should be to want to be </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/frontend/104551.html" target="_blank" style="color:#999">https//www.codepudding.com/frontend/104551.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/frontend/104550.html'>Ask why want to get twice to res. Send the correct results</a></div> <div class="detail-arr-right">Next:<a href='/frontend/104717.html'>World Wide Web Publishing external address need to restart the site can access problems</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=Ajax' target='_blank'>Ajax</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>