$config=array( ‘maxSize‘ => 3145728, ‘savePath‘ => ‘./Public/Uploads/‘, ‘rootPath‘ => ‘./‘, //这样写上传到网站根目录下的public下 ‘exts‘ => array(‘jpg‘,‘gif‘,‘png‘,‘jpeg‘), ‘autoSub‘ => true, ‘subName‘ => array(‘data‘,‘Ymd‘) ); //定义配置数组 $upload = new \Think\Upload($config); //实例化上传对象 $info = $upload -> uploadOne($_FILES[‘peitu‘]); // 执行单个图片上传,并获取上传结果 if(!$info){ $this->error($upload->getError()); }else{ $data[‘img_src‘] = $info[‘savepath‘].$info[‘savename‘]; //将上传文件的保存路径存到数据库以便前台调用 }
时间: 2024-10-10 01:48:43