在ajax中附加多个文件

I have 4 files to upload and i need to append all by name. When i try like that i get an empty array in php.

function AjaxFileUpload() {
    **var fileInput = document.getElementsByName("img");
    var file = fileInput.files[0];**
    var fd = new FormData();
    fd.append("file", file);
    var xhr = new XMLHttpRequest();
    xhr.open("POST", 'abc.php');
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4) {
             alert('success');
        }
        else if (uploadResult == 'success')
            alert('error');
    };
    xhr.send(fd);
}

Maybe change var file = fileInput.files[0]; to var file = fileInput[0];, but I'm not sure.