Hello guys, i’m new to Yii and completely newbie in Yii.
after spent some times read this article http://www.yiiframework.com/wiki/2/how-to-upload-a-file-using-a-model/ so i’m trying to create 1 form which 1 of its fields will upload the image and store its image path location into database.
here are my code,
model
return array(
array('product_price', 'numerical', 'integerOnly'=>true),
array('product_name', 'length', 'max'=>255),
array('product_img_path', 'file', 'types'=>'jpg, jpeg, png',),
array('product_specification', 'safe'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('product_id, product_name, product_specification, product_price, product_img_path', 'safe', 'on'=>'search'),
);
controller
public function actionCreate()
{
$model=new Product;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Product']))
{
$model->attributes=$_POST['Product'];
$model->product_img_path=CUploadedFile::getInstance($model,'product_img_path');
if($model->save())
$this->redirect(array('view','id'=>$model->product_id));
$model->product_img_path->saveAs('E:/Web_Project/store/product_images/');
}
$this->render('create',array(
'model'=>$model,
));
}
_form file
<div class="row">
<?php echo $form->labelEx($model,'product_img_path'); ?>
<?php echo $form->fileField($model,'product_img_path'); ?>
<?php echo $form->error($model,'product_img_path'); ?>
</div>
there is no error appear but image won’t uploaded and path won’t stored.
please help me where i made a wrong.
thank you.