首页 > 代码库 > thinkphp生成多张缩略图
thinkphp生成多张缩略图
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生成多张缩略图