i am trying to send a file through xmlhttprequest and process it on the server through PHP, i cannot use jQuery.
Here is my javascript
xhr = new XMLHttpRequest();
xhr.open("POST", $("upload").action, true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader("X_FILENAME", file.newname || file.name);
xhr.setRequestHeader("CONTENT_TYPE", file.type);
xhr.send("userfile=" + file + "&" + $('upload').serialize());
it happens that on my PHP the $_FILES is empty and the $_POST along with the form data holds the variable userfile which is marked as "object file".
So now my questions are:
- Does the variable userfile really holds the content of the file i am trying to upload?
- How can i copy the value in userfile to a file on my server?
This is what I tried so far:
file_put_contents($tmpfile, $userfile);
but it does not seem to copy correctly the value into $tmpfile.
I hope I was clear enough
Thanks in advance
Best regards