thinkphp3.2.3 register to upload pictures

不言
Release: 2023-03-25 08:28:02
Original
2000 people have browsed it

This article mainly introduces about thinkphp3.2.3 registration and uploading images, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

//文件上传
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     './Public/Shop'; // 设置附件上传根目录
        $upload->savePath  =     ''; // 设置附件上传(子)目录
        // //上传单个图像
        $info = $upload->uploadOne($_FILES['image']);
        if(!$info) {
            // 上传错误提示错误信息
            $this->error($upload->getError());
        }
        else{
            // 上传成功 获取上传文件信息
            $image='/shop'.$info['savepath'].$info['savename'];
            $data['image'] = $image;       //变量赋值 
            $users = M('user');      //获取user表
            $data['name'] = I('name');      //变量赋值
            $data['pass'] = I('pass');      //变量赋值
            $data['phone'] = I('phone');        //变量赋值
            $data['qq'] = I('qq');      //变量赋值
            $data['create_time'] = time();      //变量赋值,获取当前时间
            $data['role'] = I('role');      ////变量赋值
            //查询数据库单条记录
            $row = $users->where(array('name'=>$data['name']))->find();
            $code= I('post.wan');                //这是提取页面上打字输入的code即验证码
            if(check_code($code) === false){       //给function.php中定义的函数check_code,然后它返回真假
                $this->error('验证码错误');
            } 
            else{
                //判断    
                if($row['name'] == $data['name']){      //判断获取的值等于数据库中的值
                        $this->error('注册失败');     //上面判断成立,则失败跳转
                }
    
                elseif($row['name']!=$data['name']){       //判断获取的值不等于数据库中的值
                       if($data !=null ){      //判断数据不为null   
                            $row = $users->data($data)->add();      //判断成立插入数据
                            $this->success('注册成功!',U('User/login'),3);     //成功跳转
                        }
                }
            }
       }
Copy after login
头 像:<input type="file" name="image"/><br><br/>
Copy after login

Related recommendations:

thinkphp3.2.3 Integrate phpExcel export data

ThinkPHP3.2.3 page static implementation method


The above is the detailed content of thinkphp3.2.3 register to upload pictures. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template