ajax文件上传问题

发布于 2024-12-19 22:55:24 字数 640 浏览 0 评论 0原文

我已经被这个问题困扰了一段时间了。

我需要实现一个简单的ajax文件上传到服务器,而不向用户显示文件形式并立即呈现上传的图片 我一直在尝试使用这个插件: http://valums.com/ajax-upload/ ,但它不起作用。 请求成功到达服务器(然后返回客户端),但是当我尝试访问 $_FILES 数组(是的,它是 PHP)时,它是空的!

管理发送的代码是这样的:

    xhr.open("POST", queryString, true);
    xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
    xhr.setRequestHeader("X-File-Name", encodeURIComponent(name));
    xhr.setRequestHeader("Content-Type", "application/octet-stream");
    xhr.send(file);

我一直在尝试用谷歌搜索这个问题,但是所有链接都一致说,你不能使用 XHR 上传文件。但这个插件似乎非常流行并且合法 - 那么,我做错了什么? 谢谢!

i've been stuck with this problem for a while.

I need to realize a simple ajax file upload to server, without showing the user a file form and immediate presentation of the uploaded picture
I've been trying to use this plugin: http://valums.com/ajax-upload/, but it doesn't work.
The request succesfully reaches the server (and then returns to client), but when I'm trying to access $_FILES array (yes, it's PHP), it is empty!

The code that manages sending is this:

    xhr.open("POST", queryString, true);
    xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
    xhr.setRequestHeader("X-File-Name", encodeURIComponent(name));
    xhr.setRequestHeader("Content-Type", "application/octet-stream");
    xhr.send(file);

I've been trying to google this problem, but all links in unison say, that you can't upload files with XHR. But this plugin seems to be pretty popular and legit - so, what am I doing wrong?
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇俏 2024-12-26 22:55:24

使用新的 HTML5 filereader API 读取文件并使用 XHR 发送它,我认为这与使用 $_FILES 的 HTTP 文件上传不同。数据经过base64编码并通过POST方法发送。

Reading file with the new HTML5 filereader API and sending it with XHR, I don't think it is the same as HTTP file upload in which case $_FILES is used. The data is base64encoded and sent with POST method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文