i have an Ionic app that lets users upload 5 videos to the server in order to get one video compilation of their videos. So far i can upload only one video and grab it in my php silex API.
This is my i’m doing
_upload(index){
console.log(index);
if(index >= this.favorites.length) return;
this.http
.uploadFile(this.apiLink + ‘user/upload’, {}, {}, this.favorites[index], ‘file’)
.then(data => {
if(index == this.favorites.length) this.loaderBox.dismiss();
console.log("Done for index : "+index+"| data :"+JSON.stringify(data));
this._upload(index + 1);
})
.catch(err => {
console.error("Error index “+index+” | error "+JSON.stringify(err));
})
}
PHP code
$app->post(’/user/upload’, function(Request $request) use($app) {
session_start();
$file = $request->files->get(‘file’);
if( !isset($_SESSION[‘files’]) )
{
$_SESSION[‘files’] = [];
}
$files = $_SESSION[‘files’];
array_push($files,$file);
$_SESSION[‘files’] = $files;
if(count($_SESSION[‘files’]) == 5){
$rsp = upload($_SESSION[‘files’]);
$_SESSION[‘files’] = [];
return $app->json(array(‘response’=>$rsp));
}
});