通过AJAX使用PHP上传文件 [英] uploading a file via ajax with php

查看:127
本文介绍了通过AJAX使用PHP上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能上传通过AJAX和PHP的二进制文件,并有一个链接下载它。我想,以避免刷新整个页面,与一个标准的HTML表单。到目前为止,我一直在使用的形式来获取信息,如广播和文本框,并使用JavaScript来覆盖默认行为。是类似的事情可能上传一个文件?

I would like to know if it is possible to upload a binary file via ajax and php, and have a link to download it. I would like to avoid refreshing the entire page, as with a standard html form. So far I have been using forms to get information, such as radio and text boxes, and using javascript to override the default behavior. Is a similar thing possible for uploading a file?

推荐答案

这是不可能通过JavaScript提交文件。

It isn't possible to submit a file through Javascript.

您的选择是:

  • 在隐藏的iframe把戏,由谷歌推广。实现这个自己可能会导致一些klunky东西,所以有图书馆在那里,如 jQuery的,其中有插件,如jQuery的流行表格插件,能自动完成这些,所以你不必觉得脏的时候使用它里面。
  • 使用闪光灯,旨在便利进程。最值得注意的是 SWFUpload的是非常受欢迎的。所有的事情都是平等的,我可能会用JavaScript解决方案在这一去,但我已经在过去成功使用此。这个解决方案的很酷的事情是,它配备了一个更好的接口,如负载指标和缩略图和这样的。在这一点上,虽然,你要求用户安装Flash + Javascript的可用,这可能无法在某些情况下工作。
  • 使用Silverlight而不要使用闪光灯,虽然我不会真的认为这是一个可行的解决方案,因为它有一个低得多的普及率比其他两种解决方案。
  • The hidden iframe trick, popularized by Google. Implementing this yourself can result in some klunky stuff so there are libraries out there, such as jQuery, which have plugins, such as jQuery's popular Form Plugin, that automate this so you don't have to feel dirty inside when using it.
  • Using Flash to faciliate the process. Most notably SWFUpload is very popular. All things being equal, I'd probably go with the Javascript solution over this, but I've used this in the past with success. The cool thing about this solution is that it comes with a nicer interface such as loading indicators and thumbnails and such. At this point, though, you're asking for a user to have Flash + Javascript available, which may not work in some situations.
  • Using Silverlight instead of Flash, although I wouldn't really consider this as a viable solution, as it has a much lower penetration rate than the other two solutions.

这篇关于通过AJAX使用PHP上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆