Browse Source

朋友圈上传图片视频接口,视频切片保存返回

author
wanghongjun 8 months ago
parent
commit
ec52508b0a
  1. 28
      app/common/controller/Upload.php
  2. 24
      app/enterprise/controller/Posts.php

28
app/common/controller/Upload.php

@ -110,6 +110,17 @@ class Upload extends BaseController
'user_id'=>$uid,
'videoInfo'=>$imageInfo
];
// 上传视频切片
if ($fileType == 4) {
$videoInfo=$this->getVideoCover($filePath);
if($videoInfo){
$poster=$this->url.$videoInfo['src'];
}else{
$poster=getMainHost().'/static/common/img/video.png';
}
$ret['poster'] = $poster;
}
if($message){
// 自动获取视频第一帧,视频并且是使用的阿里云
@ -204,6 +215,23 @@ class Upload extends BaseController
}
}
// 上传图片
public function uploadPosts(){
$param=request::param();
try{
$file=request()->file('file');
$info=$this->upload($param,$file);
$url=$this->url.$info['src'];
$data = ['url' => $url, 'poster' => ''];
if (isset($info['poster'])) {
$data['poster']=$this->url.$info['poster'];
}
return success(lang('file.uploadOk'),$data);
} catch(\Exception $e) {
return error($e->getMessage());
}
}
// 普通上传头像
public function uploadAvatar(){
$param=request::param();

24
app/enterprise/controller/Posts.php

@ -176,7 +176,7 @@ class Posts extends BaseController
$privacy = $this->request->param('privacy', '');
$location = $this->request->param('location', '');
$address = $this->request->param('address', '');
$video_file = $this->request->param('video_file', '');
$video_file = $this->request->param('video_file', []);
$imgArr = $this->request->param('img_arr', []);
$posts_id = $this->request->param('posts_id', '');
$user_ids = $this->request->param('user_ids', []);
@ -249,16 +249,18 @@ class Posts extends BaseController
}
if (!empty($video_file)) {
$videoUrl = str_replace($this->url, '', $video_file);
$whereFile = ['src' => $videoUrl, 'user_id' => $this->uid, 'delete_time' => 0];
$video_file_id = File::where($whereFile)->value('file_id');
if ($video_file_id) {
$fileSaveArr[] = [
'posts_id' => $posts_id,
'type' => 2,
'file_id' => $video_file_id,
'sort' => 1
];
foreach ($video_file as $v_file) {
$videoUrl = str_replace($this->url, '', $v_file);
$whereFile = ['src' => $videoUrl, 'user_id' => $this->uid, 'delete_time' => 0];
$video_file_id = File::where($whereFile)->value('file_id');
if ($video_file_id) {
$fileSaveArr[] = [
'posts_id' => $posts_id,
'type' => 2,
'file_id' => $video_file_id,
'sort' => 1
];
}
}
}

Loading…
Cancel
Save