我有一个Ionic 3应用程序,该应用程序应一次将5个视频上传到我的PHP API。
目前,我只能使用Ionic的Http插件发送一个视频。如何一次上传所有视频?
let body = new FormData();
body.append('file1', this.favorites[0]);
body.append('file2', this.favorites[1]);
body.append('file3', this.favorites[2]);
body.append('file4', this.favorites[3]);
body.append('file5', this.favorites[4]);
this.http
.uploadFile(this.apiLink+"user/upload",body,{},"","")
.then(data => {
// Do something
})
.catch(error => {
// Catch error
});}
这是我的PHP代码
//Upload file
$app->post("/user/upload", function (Request $request) use ($app) {
$file1 = $request->files->get('file1');
$file2 = $request->files->get('file2');
$file3 = $request->files->get('file3');
$file4 = $request->files->get('file4');
$file5 = $request->files->get('file5');
$files = [];
array_push($files,$file1);
array_push($files,$file2);
array_push($files,$file3);
array_push($files,$file4);
array_push($files,$file5);
$rsp = upload($files);
return $app->json(array('response'=>sizeof($files)));
});