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


     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 ThinkUpload();
    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 ThinkImage(); 
    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 }
  • 相关阅读:
    uniapp开发注意事项
    uniapp生成海报带二维码及保存
    严格模式的this
    数据类型
    短路特性
    第九周程序改错
    矩阵转置
    二分法求根
    三天打鱼两天晒网
    LeetCode7
  • 原文地址:https://www.cnblogs.com/qiuphp/p/7543595.html
Copyright © 2020-2023  润新知