前端视频模块显示空白
起因
由于短视频上传后路劲不正确导致前台无法正常显示,地址拼接有错
解决方案
更新v3.0.2后 视频上传处理部分进行了调整,可直接覆盖songshu-jhlive-admin/application/admin/controller/Video.php 文件
具体代码参考如下
onlyAdmin(); $file = request()->file('file'); $oldfile = input("oldfile"); if($file){ //图片可以是20M以内 $info = $file->validate(['size'=>20480000,'ext'=>'jpg,png,gif,jpeg'])->move(ROOT_PATH . 'public/uploads'); if($info){ $exif = exif_read_data(ROOT_PATH . 'public/uploads/'.$info->getSaveName()); $image = Image::open(ROOT_PATH . 'public/uploads/'.$info->getSaveName()); if(!empty($exif['Orientation'])) { switch($exif['Orientation']) { case 8:$image = $image->rotate(-90);break; case 3:$image = $image->rotate(180);break; case 6:$image = $image->rotate(90);break; } } $width = $image->width(); $height = $image->height(); $_height = $width ? $height/$width * 400 : 0; $filepath = $info->getSaveName(); $filepath = str_replace("\\","/",$filepath); $image->thumb(400, $_height)->save(ROOT_PATH . 'public/uploads/'.$filepath); if(strlen($oldfile) && strpos($oldfile,"uploads/") === 0){ @unlink(ROOT_PATH . 'public/'.$oldfile);//删除旧图片 } $this->success(['filepath'=>config('storage_url').'uploads/'.$filepath]); }else{ // 上传失败获取错误信息 $this->error($file->getError()); } } $this->error("未上传图片"); } public function upload_video(){ $this->onlyAdmin(); $file = request()->file('file'); $oldfile = input("oldfile"); if($file){ //视频可以是200M以内 $info = $file->validate(['size'=>204800000,'ext'=>'avi,mpg,mpeg,mpe,m1v,m2v,mpv2,mp2v,dat,ts,tp,tpr,pva,pss,mp4,m4v,m4p,m4b,3gp,3gpp,3g2,3gp2,ogg,mov,qt,amr,rm,ram,rmvb,rpm'])->move(ROOT_PATH . 'public/uploads'); if($info){ $filepath = $info->getSaveName(); $filepath = str_replace("\\","/",$filepath); if(strlen($oldfile) && strpos($oldfile,"uploads/") === 0){ @unlink(ROOT_PATH . 'public/'.$oldfile);//删除旧视频 } $this->success(['filepath'=>config('storage_url').'uploads/'.$filepath]); }else{ // 上传失败获取错误信息 $this->error($file->getError()); } } $this->error("未上传图片"); } public function save_video() { $this->onlyAdmin(); if (!request()->isPost()) $this->error('请求类型有误'); $id = input("id"); $video = Db::name("videos")->where("id", $id)->find(); $title = input('title'); $img = input('imageurl'); $address = input('videourl'); if (strlen($title) == 0) $this->error("请填写一个标题"); if (strlen($img) == 0) $this->error("请填上传一张封面照片"); if (strlen($address) == 0) $this->error("视频地址不能为空"); if ($video) { $data = array(); $data['title'] = $title; $data['img'] = $img; $data['address'] = $address; $data['update_time'] = time(); if (Db::name("videos")->where("id",$video['id'])->update($data)) { $this->success(NULL, "视频更新成功"); } else { $this->error("视频更新未成功"); } } else { $data = array(); $data['title'] = $title; $data['img'] = $img; $data['address'] = $address; $data['create_time'] = time(); if (Db::name("videos")->insert($data)) { $this->success(NULL, "视频发布成功"); } else { $this->error("视频发布未成功"); } } } public function getlist(){ $this->onlyAdmin(); $db = Db::name("videos")->field('id,title,img,create_time,update_time,collect_times'); $keyword = input("keyword"); if(strlen($keyword)){ $db = $db->where("title","like","%".addslashes($keyword)."%"); } $db = $db->order("id","desc"); $list = $db->paginate(10); $list->each(function ($item,$key){ $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']); $item['update_time'] = $item['update_time'] ? date('Y-m-d H:i:s',$item['update_time']) : '从未更新'; return $item; }); $this->success($list); } public function get_video(){ $this->onlyAdmin(); $video = Db::name("videos")->where("id",intval(input("id")))->find(); if(!$video) $this->error("未找到相关视频"); $this->success($video); } public function delete(){ $this->onlyAdmin(); $video = Db::name("videos")->where("id",intval(input("id")))->find(); if(!$video) $this->error("未找到相关视频"); if(Db::name("videos")->where("id",$video['id'])->delete()){ $img = $video['img']; $address = $video['address']; if(strpos($img,"uploads/") === 0) @unlink($img); if(strpos($address,"uploads/") === 0) @unlink($address); $this->success(NULL,"删除成功"); }else{ $this->error("删除失败"); } }}
更新后
songshu-jhlive-admin/application/config.php 多了一行
'storage_url'=>'https://jh.youyacao.com/', // 应用调试模式 'app_debug' => true, // 应用Trace 'app_trace' => false, // 应用模式状态 'app_status' => '', // 是否支持多模块 'app_multi_module' => true, // 入口自动绑定模块 'auto_bind_module' => false, // 注册的根命名空间 'root_namespace' => [], // 扩展函数文件 'extra_file_list' => [THINK_PATH . 'helper' . EXT], // 默认输出类型 'default_return_type' => 'json', // 默认AJAX 数据返回格式,可选json xml ... 'default_ajax_return' => 'json', // 默认JSONP格式返回的处理方法
storage_url 对应填写自己的域名即可。
松鼠聚合直播系统下载地址:
https://download.csdn.net/download/dujiangdu123/86839877
来源地址:https://blog.csdn.net/dujiangdu123/article/details/127576592