【发布时间】:2021-02-26 21:22:30
【问题描述】:
在我的 vue 和 php 应用程序中一次上传多个文件时遇到了一些麻烦。我正在使用 slim 来发布上传请求的端点: 在服务器端,我有这段代码来测试是否一切正常:
$app->post('/compress', function(Request $request, Response $response){
$files = $request->getUploadedFiles();
var_dump($files); // this will result in empty
//return $response;
});
在我的 javascript 代码中,在一个 vue 方法中,我有这个代码,当文件输入发生变化时会调用它:
let formData = new FormData();
for(let i; i < this.$refs.selectedImages.files.length; i++){
formData.append('images[]', this.$refs.selectedImages.files[i]);
}
let config = {
header: {
'Content-Type': 'multipart/form-data',
},
withCredentials: true
}
axios.post('http://localhost:3000/compress', formData, config)
.then( (response) => {
console.log(response, response.data);
});
结果是var_dump 会给我空。我该如何解决?
【问题讨论】: