I’ve this JavaScript code to upload a file
// Uploading - for Firefox, Google Chrome and Safari
xhr = new XMLHttpRequest();
xhr.open("post", "pro/upload.php", true);
// Set appropriate headers
xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.setRequestHeader("X-File-Name", file.fileName);
xhr.setRequestHeader("X-File-Size", file.fileSize);
xhr.setRequestHeader("X-File-Type", file.type);
// Send the file (doh)
xhr.send(file);
Now how do I catch the file at upload.php?
I tried with global $_FILES["file"] variable but an error says “Undefined Index”. Does that mean the global variable is not set?
You should pass in Content-Disposition as well in setRequestHeader
Ref Link: Content-Disposition Reference