i have table in Mysql tbl_image(id(int) , ,image(varchar))
created model and crude for it .
trying to upload an image in a location D:\xampp\htdocs\wikiwin\images from another location
on browser navigating to http://localhost/wik...image/view&id=1
it gives me browse option but how to upload at location after giving image path ----"or how it will upload…No button is there for this".
for this i tried like that:
In Model file--------------
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('image', 'required'),
array('image', 'length', 'max'=>300),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('ID, image', 'safe', 'on'=>'search'),
array('image', 'file', 'types'=>'jpg, gif, png'),
);
in controller file----------------
public function actionCreate()
{
$model=new Image;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Image']))
{
$model->attributes=$_POST['Image'];
$model->image=CUploadedFile::getInstance($model,'image');
if($model->save())
$model->image->saveAs(Yii::app()->basePath . '/D:\xampp\htdocs\wikiwin\images' . $model->image);
//$model->image->saveAs('D:\xampp\htdocs\wikiwin\images');
$this->redirect(array('view','id'=>$model->ID));
}
$this->render('create',array(
'model'=>$model,
));
in correspondig view.php file--------
[b]
[/b]
<?php echo CHtml::form(’’,‘post’,array(‘enctype’=>‘multipart/form-data’)); ?>
…
<?php echo CHtml::activeFileField($model, ‘image’); ?>
…
<?php echo CHtml::endForm(); ?>