(as asked by so to clarify why my question is not duplicated of suggested post )
IMHO My question is not duplicate to that question since
- I am suing JavaScript and Ajax which linked question does not
- though I have tried solution of that post which doesn't worked
I am using ajax and to make ajax request I am using javaScript
HTML
<input id="file" type="file" name="our-file" />
<input type="button" value="Upload" id="upload-button" />
Js
var inputFile = document.getElementById("file"),
uploadButton = document.getElementById("upload-button");
uploadButton.onclick = function () {
console.log(inputFile.files[0])
var file = inputFile.files[0];
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = stateHandler;
httpRequest.open("POST", "upload.php", true);
httpRequest.setRequestHeader("X-File-Name", file.name);
httpRequest.send(file)
function stateHandler() {
var status = {
"httpRequest ready state": httpRequest.readyState,
"status": httpRequest.status,
"httpRequest responseText":httpRequest.responseText
};
console.log(status);
console.log(httpRequest.responseText);
}
}
now when I try to get uploaded file via $_FILES
I get empty array but
$_SERVER
have complete file information, is it because I have only sent header not file itself ?
screeshot of my output with $_SERVER
https://i.stack.imgur.com/1GMdh.png
screen shot of my output with $_FILES
https://i.stack.imgur.com/IECUt.png
thanks and I don't want jquery suggestion (I think its good to know language before framework developed by it :)