1:php终端

安装扩展

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

composer require topthink/think-image
2:控制器代码:
    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');
}


最新文章

  1. JavaScript权威指南 - 函数
  2. SQL Server-简单查询示例(十一)
  3. reverse array java
  4. Best Time to Buy and Sell Stock
  5. 如何实现ASP.NET中网站访问量的统计
  6. KMP算法的java实现
  7. UITabbarController左右滑动切换标签页
  8. 《 iPhone X ARKit Face Tracking 》
  9. iOS学习——Xcode9上传项目到GitHub
  10. 实验与作业(Python)-03 Python程序实例解析
  11. 简单上手nodejs调用c++(c++和js的混合编程)
  12. 关于 永恒之蓝 和 MS17-010 补丁
  13. scp断点续传
  14. Flex组件参考 代码参考汇总
  15. day24类的继承
  16. 基于Ip的刷投票排名及刷百度推广的自动化实现
  17. Project facet jst.web.jstl has not been defined.
  18. Java基础-进制转换
  19. Shell脚本中点号+文件名的作用
  20. kafka 报Failed to load class "org.slf4j.impl.StaticLoggerBinder".[z]

热门文章

  1. 洛谷P4859 已经没有什么好害怕的了
  2. AT2164 [AGC006C] Rabbit Exercise
  3. ForkJoinPool简单使用
  4. 错误代码 insufficient-isv-permissions 错误原因: ISV权限不足
  5. Cocos2d-JS环境配置教程
  6. 远程连接MySQL报错1045解决方案
  7. webpack热更新 同时导出文件到本地
  8. NS前缀
  9. 如何使Label显示时,一行顶部居中,两行靠左显示----董鑫
  10. springcloud+gateway微服务整合swagger