When i am trying to upload imgage file to projectfolder\uploaded
directory i got error
Fatal error: Call to a member function saveAs() on string
My controller code is as below
public function actionStore()
{
$model = new Article;
$this->performArticleValidation($model);
$userId = Yii::app()->user->getId();
if(isset($_POST['Article'])) {
$model->attributes = $_POST['Article'];
$model->avatar = CUploadedFile::getInstance($model,'avatar');
//var_dump($model->avatar); // Outside if
if($model->save()) {
//var_dump($model->avatar); // Inside if
$path = Yii::app()->basePath . '/../uploaded';
$model->avatar->saveAs($path);
EUserFlash::setSuccessMessage('Thank you.');
$this->redirect(array('index'));
}
}
}
Model is as below
public function rules() {
return array(
array(['avatar'], 'file', 'skipOnEmpty' => false, 'types' => 'jpg, jpeg, gif, png'),
);
}
When I tried to debug $model->avatar
outside if condition it gives me an array of an object as shown in below image and inside if it gives me the string.