不多说直接上代码

//文件上传
public function upload(){
    $files = request()->file();
    if (is_array($files)) {
        foreach ($files as $key=>$vo) {
            $info=$vo->getInfo();
            $type=substr($info['type'],0,strpos($info['type'], '/'));
            if ($type=='image'){
                $path=config('api.imagepath');
            }
            if ($type=='video'){
                $path=config('api.mediapath');
            }
            if (empty($path)){
                return getResFalse(-1,'文件格式有误');
            }
            $info = $vo->validate(['size'=>156780000,'ext'=>'jpg,png,gif,mp4'])->move($path);
            if ($info) {
                $infopath=str_replace("\\","/",$info->getSaveName());//tp5.1windows上传有反斜杠,处理下
                if ($type=='image'){
                    $imgpath=$path.'/';
                    $image = \think\Image::open($imgpath.$infopath);
                    $thumb_path = $infopath.'_20x20.'.$info->getExtension();
                    $image->thumb(20,20)->save($imgpath.$thumb_path);
                    $data[$key]['file'] = config('api.showimagepath').$infopath;
                    $data[$key]['compress_file'] = empty($thumb_path)? '':config('api.showimagepath').$thumb_path;
                }
                if ($type=='video'){
                    $data[$key]['file'] = config('api.showmediapath').$infopath;
                    $data[$key]['compress_file'] = empty($thumb_path)? '':config('api.showmediapath').$thumb_path;
                }
            } else {
                // 上传失败获取错误信息
                return getResFalse(-1,$vo->getError());
            }
        }
        $result=[
            'list'=>$data
        ];
        return getResTrue('上传成功',$result);
    } else {
        return getResFalse(-1,'缺少图片');
    }
}