This is my first time and I’m new for yii framework.
I want to store images in blob field of my database. I googled and tried. But I’ve had no luck. Every time I got error messages. I’m new for yii. So I can’t find the error also… can anyone help me please…
Please read these wikies hope it’ll help you. Saving files to a blob field in the database and Storing your images in your table’s blob field and displaying that stored images.
I tried for This . But it gives error "Property "CActiveForm.type" is not defined.".
This is my _form.
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'image-table-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
'method'=>'post',
'type'=>'horizontal',
'htmlOptions'=>array(
'enctype'=>'multipart/form-data'
)
)); ?>
This is my controller
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['ImageTable']))
{
$model->attributes=$_POST['ImageTable'];
if(!empty($_FILES['image_table']['tmp_name']['image']))
{
$file = CUploadedFile::getInstance($model,'image');
$model->fileName = $file->name;
$model->fileType = $file->type;
$fp = fopen($file->tempName, 'r');
$content = fread($fp, filesize($file->tempName));
fclose($fp);
$model->image = $content;
}
$model->user = Yii::app()->user->id;
if($model->save())
$this->redirect(array('view','id'=>$model->image_id));
}
$this->render('update',array(
'model'=>$model,
'types'=>Type::model()->findAll()
));
}
this is my model
array('image', 'file',
'types'=>'jpg, gif, png, bmp, jpeg',
'maxSize'=>1024 * 1024 * 10, // 10MB
'tooLarge'=>'The file was larger than 10MB. Please upload a smaller file.',
'allowEmpty' => true
),
there no type attribute on CActiveForm comment it out like so
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'image-table-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
'method'=>'post',
// 'type'=>'horizontal',
'htmlOptions'=>array(
'enctype'=>'multipart/form-data'
)
)); ?>