thinkphp上传图片预览并且保存到数据库,求一个代码例子!谢谢!! 30
1个回答
展开全部
/**
* @desc 保存新增广告
*/
public function saveAdd(){
$userInfo = $this->getUserInfo();
if(!$userInfo['id'] || $userInfo['id'] == 0){
$this->error('请重新登陆添加广告');
exit;
}
$_POST['user_id'] = $userInfo['id'];
if($_POST['areaType'] == 'all') unset($_POST['area']);
if( $_POST['areaType'] == 'custom' && (count($_POST['area']) == 34 || $_POST['area'] == '') ) unset($_POST['area']);
$id = null;
if($_POST['uploadType'] == 'single'){
/*$picInfo = getimagesize($_POST['pic']);
$sizeInfo = D('AdSizeConfig')->getDataById($_POST['size_id']);
if(($sizeInfo['width'] != $picInfo[0]) || $sizeInfo['height'] != $picInfo[1]){
$this->error('您上传的图片长或宽不正确!');
}*/
$id = D($this->className)->addData($_POST);
}
if($_POST['uploadType'] == 'multi'){
foreach($_POST['picArr'] as $key => $val){
$data[$key] = $_POST;
$data[$key]['pic'] = $val;
$picInfo = getimagesize("./" . $val);
$map['width'] = $picInfo[0];
$map['height'] = $picInfo[1];
$data[$key]['size_id'] = D('AdSizeConfig')->where($map)->getField('id');
$id = D($this->className)->addData($data[$key]);
}
}
if($id){
//添加广告积分,获取展示时间,获取展示区域
$diff_time_start = strtotime($_POST['start_date']);
$diff_time_end = strtotime($_POST['end_date']);
$diff_days = floor(($diff_time_end -$diff_time_start)/86400) +1;
$area_ratio = ($_POST['areaType'] == 'all') ? 5 : 1;
$uid = $userInfo['id'];
//$method = 'ad_saveadd';
//$points = -intval($diff_days) * $area_ratio;
//$desc = '这么多'.$points.'分数';
//D('ScoreHistory')->setScoreByRule($method,'',$uid,'');
$this->userAddScore();
$this->success('添加成功!','/Home/Ad/index');
}else{
$this->error( D($this->className)->getLastError() );
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询