Skip to content Skip to sidebar Skip to footer

Cannot Upload File Using Vanilla Javascript

Where am i going wrong in the script below? The back end is PHP. Something seems to be getting uploaded but the PHP script always returns the error below. I'm trying not to use for

Solution 1:

I may be wrong but usually you need to attach a file to a FormData object like this:

let fd = new FormData();
fd.append("nfile",file);
...
ajax.send(fd);

Which is then accessible in PHP using:

$_FILES["nfile"];

Post a Comment for "Cannot Upload File Using Vanilla Javascript"