This is my code, I'm trying to send a file to a PHP file but I can't. In JS the answer is that input_f.files[0] is an [object File], however PHP returns Notice: Undefined index: file... , I think that formData doesn't work.
PHP Code
<?php
$file = $_FILES['file']['size'];
echo $file;
JS Code
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);