Это мой код, я пытаюсь отправить файл в файл PHP, но не могу.В JS ответ таков: input_f.files [0] - это [объектный файл] , однако PHP возвращает Примечание: неопределенный индекс: файл ... ,Я думаю, что formData не работает.
PHP-код
<?php
$file = $_FILES['file']['size'];
echo $file;
JS-код
var text = document.getElementById('text');
var input_f = document.getElementById('input_f');//Input file
var xmlhttp = new XMLHttpRequest();
var formData = new FormData();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
text.innerHTML = this.response;
}
};
xmlhttp.open("POST","php/convert.php");
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
formData.append('file', input_f.files[0]);
xmlhttp.send(formData);