i want to upload the multiple files using "CMultiFileUpload" in YII, when i am trying to run the below code i got an error "Fatal error: Call to a member function saveAs() on a non-object in controller".
public function actionAddProductImages($id)
{
$model=new ProductImages;
if(isset($_POST['ProductImages']))
{
$files = CUploadedFile::getInstancesByName('image');
foreach ($files as $file)
{
//$rnd = rand(0,9999);
$model->attributes=$_POST['ProductImages'];
$fileName = $file->getName();
$model->image = $fileName;
$model->product_id = $id;
$model->sortorder = $_POST['ProductImages']['sortorder'];
if($model->save())
{
$files->saveAs(Yii::getPathOfAlias('webroot').'/upload/productImage/'.$fileName); // image will uplode to rootDirectory/banner/
//thumbmail---------------start---
Yii::app()->thumb->setThumbsDirectory('/upload/productImage/original/');
Yii::app()->thumb->load(Yii::getPathOfAlias('webroot').'/upload/productImage/'.$fileName)->resize(538,359)->save($fileName);
Yii::app()->thumb->setThumbsDirectory('/upload/productImage/thumb/');
Yii::app()->thumb->load(Yii::getPathOfAlias('webroot').'/upload/productImage/'.$fileName)->resize('0','110')->save($fileName);
Yii::app()->thumb->setThumbsDirectory('/upload/productImage/thumb_70/');
Yii::app()->thumb->load(Yii::getPathOfAlias('webroot').'/upload/productImage/'.$fileName)->resize('0',70)->save($fileName);
Yii::app()->user->setFlash('productImage','productImage has been added successfully');
$this->redirect(array('view','id'=>$model->image_id));
}
}
}
$this->render('create',array(
'model'=>$model,
));
}
+