2
如何用yii調整上傳圖片的大小?調整上傳圖片yii
if(isset($_POST['ArsipSurat']))
{
$rnd = rand(0,9999);
$model->attributes=$_POST['ArsipSurat'];
$uploadedFile=CUploadedFile::getInstance($model,'image');
$fileName = "{$rnd}-{$uploadedFile}"; // random number + file name
$model->image = $fileName;
if(isset($uploadedFile)){
$model->save();
//$this->redirect(array('view','id'=>$model->no_surat));
$uploadedFile->saveAs(Yii::app()->basePath.'../../images/arsip/'.$fileName);
//$this->redirect(array('admin'));
$this->redirect(array('view','id'=>$model->no_surat));
}
else if(empty($uploadedFile)) // check if uploaded file is set or not
{
$model->save();
$this->redirect(array('view','id'=>$model->no_surat));
}
else{
//$this->render('create',array('model'=>$model));
$this->redirect(array('admin'));
}
}
我有一個3000x4000像素的圖像,當直接上傳圖像時調整大小爲768x1024像素。我正在嘗試$model->resize(768, 1024);
,但是出現錯誤behaviors do not have a method or closure named "resize".