PHP AJAX 文件上传

2022-01-09 00:00:00 upload php javascript ajax

我查看了 stackoverflow 和一般互联网,但找不到简单的 AJAX 文件上传器(只是表单提交).我发现的那些不够灵活,不符合我的目的.如果我可以将此脚本调整为文件上传,那就太好了:

i've looked all over stackoverflow and the general internet and i can't find a simple AJAX file uploader (Just form submission). The ones i have found aren't flexible enough and don't fit my purpose. If i could ajust this script to file uploads, that would be great:

<script type="text/javascript">
 function upload(str)
 {
 if (str.length==0)
 { 
document.getElementById("txtHint").innerHTML="";
 return;
  }
 if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
   }
 else
   {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
 xmlhttp.onreadystatechange=function()
   {
   if (xmlhttp.readyState==4 && xmlhttp.status==200)
     {
     document.getElementById("hint").innerHTML=xmlhttp.responseText;
     }
   }
 xmlhttp.open("GET","ajax/link.php?q="+str,true);
 xmlhttp.send();
 }

在 HTML 中我会有

In the HTML i would have

<input type='file' onblur='upload(this.value)'>

谢谢

推荐答案

这里是一个简单的ajax文件上传器

Here is a simple ajax file uploader

上传

如果你不想要闪光灯,你可以使用这个;

And if you don't want flash, you may use this one;

AxUploader

相关文章