tp5 缩略图自写

发布时间:2022-07-06 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了tp5 缩略图自写脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

1:php终端

安装扩展

使用Composer安装ThinkPHP5图像处理类库:

composer require topthink/think-image2:控制器代码:
    public function save(Request $request)
    {
        //接受前端全部参数
        $data = $request->param();
//        接受文件上传
        $file = $request->file('goods_LOGo');
        if ($file) {
            $info = $file->;move(ROOT_PATH . 'public' . DS . 'uploads');
            if ($info) {
                // 成功上传后 获取上传信息
                //缩略图
                //  $filename = echo $info->getSaveName()在代码前面追加  DS .'uploads'.DS;
                $filePath = DS .'uploads'.DS.$info->getSaveName();
//              打开缩略图
               $image=Image::oPEn('.'.$filePath);
//               设置缩略图
                $image->thumb(150, 150)->save('.'.$filePath);
                $data['goods_logo'] = $filePath;
            } else {
                // 上传失败获取错误信息
                $this->error($file->getError(), 'http://www.day.COM/exam/exam/create');;
            }
        }
//        添加入库:
        $res= brand::brandId($data);
        if (!$res){
            $this->error('添加失败','http://www.day.com/exam/exam/create');
        }

        $this->success('添加成功','http://www.day.com/exam/exam/index');
    }

tp5 缩略图自写

 

 

脚本宝典总结

以上是脚本宝典为你收集整理的tp5 缩略图自写全部内容,希望文章能够帮你解决tp5 缩略图自写所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。