YII で「CMultiFileUpload」を使用して複数のファイルをアップロードしたいのですが、以下のコードを実行しようとすると、「致命的なエラー: コントローラー内の非オブジェクトでメンバー関数 saveAs() を呼び出します」というエラーが発生しました。
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,
));
}
+