Как загрузить файл на сервер по средствам ajax без использования FormData?
<form name="upload" method="POST" enctype="multipart/form-data">
<input type="file" name="myfile">
<input type="submit" value="Загрузить">
</form>
window.onload = function(){
document.forms.upload.onsubmit = function(e) {
e.preventDefault();
var file = this.myfile.files[0];
if (file) {
upload(file);
}
}
function upload(file) {
var xhr = new XMLHttpRequest();
xhr.onload = xhr.onerror = function() {
if (this.status == 200) {
console.log("success" + xhr.responseText);
} else {
console.log("error " + this.status);
}
};
xhr.open("POST", "up_file.php", true);
xhr.send(file);
}
}
На сервер отправляется Content-Type: image/png заголовок, сервер принимает данные, но не видит их как файл($_FILES - пуст). Чего не хватает в коде?