public function upload(){

      $upload = new \Think\Upload();// 实例化上传类
      $upload->maxSize = 3145728 ;// 设置附件上传大小
      $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
      $upload->rootPath = './Public/uploads/'; // 设置附件上传根目录
      $upload->savePath = ''; // 设置附件上传(子)目录
      $upload->autoSub = true;
      $upload->subName = array('date','Ymd');
      // 上传文件
      $info = $upload->upload();
      if(!$info) {// 上传错误提示错误信息
          $this->error($upload->getError());
           }else{

    //定义字符串
           $data = '';

    //循环添加并以|隔开
           foreach($info as $k){
          $data .= '/uploads/'.$k['savepath'].$k['savename'].'|';

            }

  //去掉字符串最后的|
      $data = rtrim($data,'|');

  //按照|变成数组
      $data = explode("|", $data);

  //反出数组
      return $data;
     }
}

相关文章:

  • 2021-11-26
  • 2022-01-08
  • 2021-05-09
  • 2022-01-08
  • 2022-01-08
  • 2022-01-08
  • 2022-01-08
  • 2021-10-14
猜你喜欢
  • 2022-01-08
  • 2022-01-08
  • 2022-01-23
  • 2022-01-08
  • 2022-01-08
  • 2022-01-08
相关资源
相似解决方案