码迷,mamicode.com
首页 > Web开发 > 详细

thinkphp生成多张缩略图

时间:2014-11-28 19:53:18      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:des   style   io   ar   os   sp   文件   on   bs   

public function SaveGoodsPhoto() {
import(‘ORG.Net.UploadFile‘);
$upload = new UploadFile(); // 实例化上传类
$upload->maxSize = 3145728; // 设置附件上传大小
$upload->allowExts = array(‘jpg‘, ‘gif‘, ‘png‘, ‘jpeg‘); // 设置附件上传类型
$upload->savePath = C(‘UPPATH‘) . ‘GoodsPhotos/‘; // 设置附件上传目录
$upload->thumb = true; //生成缩略图
$upload->thumbPrefix = ‘thumbx_,thumbm_,thumbd_‘;    //生成两张缩略图
$upload->thumbMaxWidth = ‘50,220,400‘;
$upload->thumbMaxHeight = ‘50,220,400‘;
if (!$upload->upload()) {// 上传错误提示错误信息
$this->error($upload->getErrorMsg());
} else {// 上传成功 获取上传文件信息
$info = $upload->getUploadFileInfo();
$gp = new GoodsPicturesModel();
$sq = $gp->where(array(
‘goods_id‘ => $this->_post(‘goods_id‘)
))->order(‘sequence desc‘)->getField(‘sequence‘);
if (isset($sq)) {
$res = $gp->add(array(
‘goods_id‘ => $this->_post(‘goods_id‘),
‘src‘ => $info[0][‘savename‘],
‘sequence‘ => $sq + 1
));
} else {
$res = $gp->add(array(
‘goods_id‘ => $this->_post(‘goods_id‘),
‘src‘ => $info[0][‘savename‘],
‘sequence‘ => 0
));
}
if ($res != FALSE) {
$this->success("上传成功!");
} else {
$this->error("上传失败!");
}
}
}

thinkphp生成多张缩略图

标签:des   style   io   ar   os   sp   文件   on   bs   

原文地址:http://www.cnblogs.com/pigmorn/p/4129115.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!