File uploading with XMLHttpRequest Undefined index
-
05-06-2023 - |
Domanda
I've searched around and could not find the answer to my problem. I've tried tons of stuff and it didnt work.
Whenever I'm sending a file via XMLHttpRequest to my swfupload.php my swfupload.php doesnt see the $_FILES
Here is my HTML
<form id="FlashUpload">
<div class="fUpload">
<label for="fileToUpload">Select a swf to Upload</label><br />
<input type="file" name="upfile" id="fileToUpload" onchange="fileSelected();" accept="application/x-shockwave-flash">
<input type="button" value="Upload" id="buttonToUpload" onclick="uploadFlash();"/>
<div id="fError"></div>
</div>
<div style=" display:none;" class="meter animate">
<span style="width: 0%;"><span></span></span>
</div>
</form>
and here is my javascript file
function uploadFlash() {
var client = new XMLHttpRequest();
var file = document.getElementById('fileToUpload');
var formData = new FormData();
formData.append("upfile", file.files[0]);
client.open("post", "/swfupload.php", true);
client.setRequestHeader("Content-Type", "multipart/form-data");
client.send(file); /* Send to server */
client.onreadystatechange = function()
{
if (client.readyState === 4 && client.status === 200) {
var return_data = client.responseText;
$("#fError").text(return_data);
}
}
}
This is the part where I get my error in PHP
if (!isset($_FILES['upfile']['error'])) {
throw new RuntimeException($_FILES['upfile']['error']);
}
I'm not sure if it has anything to do with me being in WAMP
The error:
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow