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("上传失败!");
}
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。