在我的表单提交中,我有:
var formData = new FormData();
for (var i = 0; i < ctx.files.length; i++) {
formData.append('file[]', ctx.files[i]);
}
在我的服务器端,我只是转储 $_POST。
我得到:
array(1) {
["file"]=>
array(1) {
[0]=>
string(17) "[object FileList]"
}
}
它以字符串的形式出现,我怎样才能将它作为文件数组获取?
这是整个请求:
var formData = new FormData();
for (var i = 0; i < ctx.files.length; i++) {
formData.append('file[]', ctx.files[i]);
//formData.push(ctx.files[i]);
}
// now post a new XHR request
var xhr = new XMLHttpRequest();
xhr.open('POST', '/site-manager-gateway/add-content');
xhr.onload = function () {
if (xhr.status === 200) {
console.log('all done: ' + xhr.status);
} else {
console.log('Something went terribly wrong...');
}
};
xhr.send(formData);