Browse Source

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

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

28
app/common/controller/Upload.php

@ -111,6 +111,17 @@ class Upload extends BaseController
'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){
// 自动获取视频第一帧,视频并且是使用的阿里云
if($message['type']=='video'){
@ -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();

6
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,7 +249,8 @@ class Posts extends BaseController
}
if (!empty($video_file)) {
$videoUrl = str_replace($this->url, '', $video_file);
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) {
@ -261,6 +262,7 @@ class Posts extends BaseController
];
}
}
}
if ($fileSaveArr) {
(new PostsFile())->saveAll($fileSaveArr);

Loading…
Cancel
Save