Sae平台的上传图片写法

jerry thinkphp 2015年11月19日 收藏
用thinkphp3.2.3的liaray中的Think文件下面的upload.class.php的实现,网上百度搜出来的真的是五花八门,各种各样,自己实践总结出来上传图片基于thinkphp3.2.3正确写法
  1. if (!empty($_FILES)) {
  2.                 if($_FILES['img']['size']>2*1024*1024){ 
  3.                     $this->error("上传图片大小不能大于2M");
  4.                 }
  5.                 $config=array(
  6.                     'exts'=>array('jpg','gif','png'),
  7.                     'rootPath'=>'./public/', //sae上的domain
  8.                     'savePath'=>'upload/', //sae会自动创建
  9.                     'saveRule'=>'time',
  10.                 );
  11.                 $upload = new \Think\Upload($config,'Sae');  //sae一定要写
  12.                 $upload->thumb=false;
  13.                 if (!$info=$upload->upload()) {
  14.                     echo $upload->getError();die;
  15.                     $this->error($upload->getError());
  16.                 } else {
  17.                     $_POST['img']=$info['img']['url'];
  18.                 }
  19.                 if(M("work")->add($_POST)){ 
  20.                     $this->success("提交成功",U('Index/work'));
  21.                 }else{ 
  22.                     $this->error("提交失败");
  23.                 }
  24.             }