Add photos together in Add in the Data controller
welfare
welfare 2017-08-08 11:14:48
0
3
1171

How to write the image upload code in the add in the Data controller! I can't add it according to the previous method! Can you give me a sample code? How should I add pictures to upload here? Please help

TIM截图20170808111414.png

welfare
welfare

reply all (3)
糊涂斌
public function upload(){ $upload_img=M('upload_img');//上传文件路径写入的表 if(!empty($_FILES)){ //上传单个图像 $upload = new \Think\Upload();// 实例化上传类 $upload->maxSize = 1*1024*1024 ;// 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型 $upload->rootPath = './upload/'; // 设置附件上传根目录 $upload->savePath = date('Y-m-d'); // 设置附件上传(子)目录 $upload->saveName=array('uniqid','');//上传文件的保存规则 $upload->autoSub = true;//自动使用子目录保存上传文件 $upload->subName = array('date','Ymd'); // 上传单个图片 $info = $upload->uploadOne($_FILES['image']); if(!$info) {// 上传错误提示错误信息 $this->error($upload->getError()); }else{// 上传成功 获取上传文件信息 $img_url=$info['savepath'].$info['savename']; $data['img_url']=$img_url; $data['img_name']=$info['savename']; $data['create_time']=time(); $upload_img->create($data); $result=$upload_img->add(); if(!$result){ $this->error('上传失败!'); }else{ $this->success('上传成功'); } } } }


    大家讲道理

    TP Please refer to the document for uploading image processing in the TP manual, it is written in very detail

    • reply I don’t quite understand! How do I put this into the upload image page?
      welfare author 2017-08-08 15:47:08
    ringa_lee

    In the add method, call the image upload class, and then save the uploaded image path to the database

    • reply But the database is empty and not saved. If you have time, can you help me? QQ:9 3 2 6 9 6 1 8 1
      welfare author 2017-08-08 15:46:02
    • reply After uploading your picture, can you get the name of the picture? If you can provide the name and path of the image, it will definitely be saved in the database.
      ringa_lee author 2017-08-08 16:37:16
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!