Quote:
fileData.append(files[i].name, files[i]);
You are using an undeclared variable
i
. Unless you've declared that somewhere else, it will be
undefined
, so you will get a reference error. And if you have declared it somewhere else, it almost certainly doesn't contain the value you expect it to contain.
Also,
fileUpload
is a
jQuery
object, which doesn't contain a
files
property. So that won't work either.
And based on your markup,
employeepic
is an
<img>
, not an
<input type="file">
.
Start by fixing your code:
<input type="file" id="employeepic" name="employeepic">
const fileUpload = document.getElementById("employeepic");
const files = fileUpload.files;
const fileData = new FormData();
fileData.append(fileUpload.name, files[0]);
If it still doesn't work, then check your browser's developer console for errors. If there are none, check the network requests tab to examine precisely what you are sending to the server.