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

thinkphp3.2.3----图片上传并生成缩率图

时间:2017-09-18 17:24:38      阅读:883      评论:0      收藏:0      [点我收藏+]

标签:direct   pat   mode   ted   this   com   es2017   user   uniq   

技术分享

 1 public function uploadify(){
 2     if(!IS_POST){
 3         $this->error(‘非法!‘);
 4     }
 5     $upload = $this->_upload();
 6 }
 7 
 8 protected function _upload(){
 9     $obj = new \Think\Upload();
10     $obj->exts = array(‘jpg‘, ‘gif‘, ‘png‘, ‘jpeg‘);// 设置附件上传类型
11     $obj->rootPath = ‘./data/upload/‘;    //upload类、image类的./入口目录
12     $obj->savePath = ‘face/‘;
13     $obj->saveRule = ‘uniqid‘;
14     $obj->uploadReplace = true;
15     $obj->autoSub = true;
16     $obj->subType = ‘date‘;
17     $obj->dateFormat = ‘Y_m‘;
18     $info = $obj->upload();
19     $userinfo = $this->users_model->where(array(‘id‘ => $this->userid))->find();
20     if(!$info) {// 上传错误提示错误信息
21         $this->error($obj->getError());
22     }else{// 上传成功
23         $face = ‘./data/upload/‘.$info[‘face‘][‘savepath‘].$info[‘face‘][‘savename‘];
24         // 生成缩略图128*128;
25         $image = new \Think\Image(); 
26         $image->open($face);
27         // 按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.jpg
28         $image->thumb(128, 128)->save($face);
29       M(‘users‘)->where(array(‘id‘ => $this->userid))->save(array(‘avatar‘ => $info[‘face‘][‘savepath‘].$info[‘face‘][‘savename‘]));
30       if($userinfo[‘avatar‘]){
31            @unlink(‘./data/upload/‘.$userinfo[‘avatar‘]);//删除旧图
32       }
33       redirect(U(‘user/profile/upload_face‘));
34     }
35 }

 

thinkphp3.2.3----图片上传并生成缩率图

标签:direct   pat   mode   ted   this   com   es2017   user   uniq   

原文地址:http://www.cnblogs.com/qiuphp/p/7543595.html

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