ajax文件上传问题
我已经被这个问题困扰了一段时间了。
我需要实现一个简单的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用新的 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.