I’m sending a FomData object using fetch, that contains all my form elements, including a PDF file to upload. I am successfully receiving the data in my PHP file but, How can I upload the file from the FormData object?
my JS file:
//extracts all data from my Form
const formD = new FormData($(this)[0]);
var object = {};
formD.forEach((value, key) => object[key] = value);
//sends data to the php file
fetch('/modules/editData.data.php', {
method: "POST",
headers: {
"Content-Type": "application/json; charset=UTF-8"
},
body: JSON.stringify(object)
})
.then(res => res.json())
.then(data => console.log(data));
}
});
my PHP file:
$json = file_get_contents('php://input');
$data = json_decode($json);
$fileID = $data->fileID;
$name = $data->name;
$file = ????
I have tried
if(isset($_FILES['files'])) {
echo json_encode('OK');
}
but no results where obtain. The rest of the data from the form is fine, I just need to know how to obtain the file from the FormData to use PHP move_uploaded_file