Demo entry 6357121

register

   

Submitted by anonymous on Apr 21, 2017 at 07:02
Language: PHP. Code size: 1.3 kB.

    public function register()
    {
        $userModel=D('Users');
        if($userModel->create())
        {
            if($_FILES['photo']['error']==0)//判断文件上传是否成功
            {
                $filename=$this->img();
                $userModel->photo=$filename;//获取文件的名字
            }
            if($userModel->add())
            {
                $this->success('注册成功','index');
            }
            else
            {
                $this->error('注册失败');
            }
        }
        else
        {
            $this->error($userModel->getError());
        }
    }
function img()
    {
        //图片处理函数
        $photoinfo = $this->upload();
        $filePath='./Public/Uploads/photo/';
        $imgfile=$photoinfo['photo']['rootpath'].'\\'.$photoinfo['savephoto']['savename'];
        //$filePath=$photoinfo['photo']['rootpath'];
        $oldFileName=$photoinfo['photo']['savename'];
        $olfFileFullName=$filePath."\\".$oldFileName;
        $newFileName='thumb_'.$oldFileName;
        $newFileFullName=$filePath."\\".$newFileName;

        $image=new\Think\Image();
        $image->open($olfFileFullName);
        $image->thumb(100,100)->save($newFileFullName);
        return $newFileName;
    }

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).