yii框架中文件上传, 可以上传成功,为什么数据库添加不到数据库中? 哪位大神帮我解决一下啊? QQ 465551122 10
.............(action里面的)$_POST["uid"]=Yii::app()->session['uid'];$_POST["user_name"]=...
.............(action里面的)
$_POST["uid"] = Yii::app()->session['uid'];
$_POST["user_name"] = Yii::app()->session['admin_name'];
$_POST["create_time"] = time();
$Forum->attributes = $_POST;
if($Forum->save()){
$_POST['logo'] = " ";
$_POST['img'] = " ";
$_POST["fid"] = $Forum->fid;
$cate_icon = CUploadedFile::getInstance($ForumFields,"cate_icon");
$cate_img = CUploadedFile::getInstance($ForumFields,"cate_img");
if(!empty($cate_icon)){
$_POST['logo'] = "./images/upload/".rand().time().rand().".".$cate_icon->getExtensionName();
$cate_icon->saveAs($_POST['logo']);
}
if(!empty($cate_img)){
$_POST['img'] = "./images/upload/".rand().time().rand().".".$cate_img->getExtensionName();
$cate_img->saveAs($_POST['img']);
}
#var_dump($_POST);die;
$ForumFields->attributes = $_POST;
#var_dump($ForumFields);die;
var_dump($ForumFields->save());die;
echo "<script>alert('添加成功!');location.href='".Yii::app()->homeUrl."?r=Forum/index';</script>";
}
echo "<script>alert('操作失败');history.go(-1);</script>";
}else{ ... }
..............(视图里)
<?php echo CHtml::form(Yii::app()->homeUrl.'?r=Forum/add','post',array('enctype'=>'multipart/form-data')); ?>
......
<?php echo CHtml::activeFileField($ForumFields, 'cate_icon',array('class'=>'fileinput','size'=>30)); ?>
<?php echo CHtml::activeFileField($ForumFields, 'cate_img',array('class'=>'fileinput','size'=>30)); ?>
...... 展开
$_POST["uid"] = Yii::app()->session['uid'];
$_POST["user_name"] = Yii::app()->session['admin_name'];
$_POST["create_time"] = time();
$Forum->attributes = $_POST;
if($Forum->save()){
$_POST['logo'] = " ";
$_POST['img'] = " ";
$_POST["fid"] = $Forum->fid;
$cate_icon = CUploadedFile::getInstance($ForumFields,"cate_icon");
$cate_img = CUploadedFile::getInstance($ForumFields,"cate_img");
if(!empty($cate_icon)){
$_POST['logo'] = "./images/upload/".rand().time().rand().".".$cate_icon->getExtensionName();
$cate_icon->saveAs($_POST['logo']);
}
if(!empty($cate_img)){
$_POST['img'] = "./images/upload/".rand().time().rand().".".$cate_img->getExtensionName();
$cate_img->saveAs($_POST['img']);
}
#var_dump($_POST);die;
$ForumFields->attributes = $_POST;
#var_dump($ForumFields);die;
var_dump($ForumFields->save());die;
echo "<script>alert('添加成功!');location.href='".Yii::app()->homeUrl."?r=Forum/index';</script>";
}
echo "<script>alert('操作失败');history.go(-1);</script>";
}else{ ... }
..............(视图里)
<?php echo CHtml::form(Yii::app()->homeUrl.'?r=Forum/add','post',array('enctype'=>'multipart/form-data')); ?>
......
<?php echo CHtml::activeFileField($ForumFields, 'cate_icon',array('class'=>'fileinput','size'=>30)); ?>
<?php echo CHtml::activeFileField($ForumFields, 'cate_img',array('class'=>'fileinput','size'=>30)); ?>
...... 展开
2个回答
展开全部
没有看到$Forum->cate_img=$cate_img这样的属性赋值语句啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询