dongzhan3937 2018-07-13 09:15
浏览 89

将多个视频从Ionic上传到PHP API

i have an Ionic app that lets a user take 5 videos and upload them to my PHP API, the PHP API expects 5 videos in the POST request so it will generate a compiled one and send the link to it back to the user.

The compilation part in the API is working, i'm using POSTMAN to test it, but i cannot upload the multiple videos to the API.

I'm using Ionic Http Plugin's uploadFile method, i can upload 1 video successfully but not all the 5 ones, tried using a loop but it is not working.

Ionic Code (Ionic 3)

  let j = 0;
  for( j = 0; j < this.favorites.length; j++){
    this.http
    .uploadFile(this.apiLink+"user/upload",{},{},this.favorites[j],"file")
    .then(data => { 
      console.log("Data" + data); 
    })
    .catch(error => { 
      console.log("Error" + error);  
    });
  }}

PHP Code (PHP 5 with Silex framework)

$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'=>$rsp));

});
  • 写回答

1条回答 默认 最新

  • douzhen5158 2018-07-13 09:25
    关注
    $file1 = $request->file('dd_upload');
    $file2 = $request->file('pan_upload');
    $file3 = $request->file('aadhar_upload');
    $file4 = $request->file('passbook_upload');
    $file5 = $request->file('signature');
    
    if(!empty($file1) && !empty($file2) && !empty($file3) && !empty($file4) && 
    !empty($file5)){
    
    $fileName1 = $file1->getClientOriginalName();
    $fileName2 = $file2->getClientOriginalName();
    $fileName3 = $file3->getClientOriginalName();
    $fileName4 = $file4->getClientOriginalName();
    $fileName5 = $file5->getClientOriginalName();
    
    $destination = 'public/uploads/docs/'. Auth::user()->customer_id;
    
    $file1->move($destination,$fileName1);
    $file2->move($destination,$fileName2);
    $file3->move($destination,$fileName3);
    $file4->move($destination,$fileName4);
    $file5->move($destination,$fileName5);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 5037端口被adb自己占了
  • ¥15 Error in check.length("fill") : 'gpar'成分'fill'的长度不能为零
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误