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