dd

Sae平台的上传图片写法

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