Home > Backend Development > PHP Tutorial > ThinkPHP中上传图片顺利,但是数据库字段内容是NULL

ThinkPHP中上传图片顺利,但是数据库字段内容是NULL

WBOY
Release: 2016-06-13 11:26:32
Original
1003 people have browsed it

ThinkPHP中上传图片成功,但是数据库字段内容是NULL
ThinkPHP中上传图片成功,但是数据库字段内容是NULL

 Public function upload(){
    import('ORG.Net.UploadFile');
    $upload = new UploadFile();// 实例化上传类
    $upload->maxSize  = 3145728 ;// 设置附件上传大小
    $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
    $upload->savePath =  './Public/Uploads/';// 设置附件上传目录
    if(!$upload->upload()) {// 上传错误提示错误信息
    $this->error($upload->getErrorMsg());
    }else{// 上传成功 获取上传文件信息 
    $info =  $upload->getUploadFileInfo();
    }
    // 保存表单数据 包括附件数据
    $User = M("Photo"); // 实例化User对象
    $User->create(); // 创建数据对象
    $User->photo = $info[0]['tupian']; // 保存上传的照片根据需要自行组装
    $User->add(); // 写入用户数据到数据库
    $this->success('数据保存成功!');
    }

  怎样重命名上传的图片,并成功插入到数据库中

上传 图片 数据库 thinkphp
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