用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元