<form id="form_test" class="test_form"
enctype="multipart/form-data" method="post" name="fileinfo">
<label>Your email address:</label>
<input id="name_form" class="input_test_form" type="email" autocomplete="on" autofocus name="userid" placeholder="email" required size="32"
maxlength="64" /><br />
<label>Custom file label:</label>
<input id="phone_form" class="input_test_form" type="text" name="filelabel" size="12" maxlength="32" /><br />
<label>File to stash:</label>
<input id="phone_img" class="input_test_form" type="file" name="file" required />
<input class="test_button" type="submit" value="Stash the file!" />
<div class="test"></div>
</form>
var form = document.forms.namedItem("fileinfo");
form.addEventListener('submit', function (ev) {
var oOutput = document.querySelector(".test"),
oData = new FormData(form);
oData.append("myfile","filename.txt");
var oReq = new XMLHttpRequest();
oReq.open("POST", "/connection.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
oOutput.innerHTML = "Загружено!";
} else {
oOutput.innerHTML = "Ошибка " + oReq.status + " при загрузки файла.<br \/>";
}
};
oReq.send(oData);
console.log(oData);
ev.preventDefault();
}, false);