我发送文件以便使用FormData上传到PHP
for (var i = 0; i < $scope.files.length; i++)
{
var file = $scope.files[i];
console.log(file);
formData.append('photos[]', file);
};
console.log(formData);
并收到此
[{"name":["file1.jpg","file2.jpg"],"type":["image\/jpeg","image\/jpeg"],"tmp_name": ["C:\\wamp\\tmp\\phpEF58.tmp","C:\\wamp\\tmp\\phpEF78.tmp"],"error":[0,0],"size":[58286,250352]}]
你可以看到它不对。我希望它如何:
[{"name": "file1.jpg", "type": "image\/jpeg",...,...},{"name": "file2.jpg", "type": "image\/jpeg",...,...}
我如何使用此功能进行上传?我甚至不确定这是我需要它..
解决了:
jQuery.each($('input[type=file]')[0].files, function(i, file)
{
formData.append(i, file);
});