opportunato
opportunato

Reputation: 631

Problems with ajax file upload

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!

Upvotes: 0

Views: 495

Answers (1)

zuo
zuo

Reputation: 1091

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.

Upvotes: 1

Related Questions