首页 >php教程 >php手册 >Sae平台的上传图片写法

Sae平台的上传图片写法

WBOY
WBOY原创
2016-06-07 11:38:541037浏览

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

AD:真正免费,域名+虚机+企业邮箱=0元

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn