I'm building a little web-app where I'd like the users to be able to upload files, I'm using FormData to do so, /
<input id="fileInput" type="file">
var formData = new FormData()
var request = new XMLHttpRequest();
request.onreadystatechange = function () {window.resp = this}
request.open("POST", "upload.php");
request.send(formData);
But I have no idea how to get the data using PHP. I know you can normally do
$_POST["KEY"]
But in this case I'm not using a key because the data isn't a string.
I've searched for quite some time now and came across the following things
print_r($_POST) // returned an empty array
var_dump($_POST) // returned an empty array
I don't know what I'm doing wrong and it's probably just some thing you have to know, but I can't seem to figure it out. Thanks in advance.
EDIT Turns out you can just get the file using the
$_FILES
global, huge thanks to @tobias K!
SOURCES: https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects