2014-08-28 177 views

回答

1

嘗試[UploadBehavior][1]加上幾行,在beforeSave功能,線路252

list($imgWidth, $imgHeight) = getimagesize($model->data[$model->alias][$field]['tmp_name']);  
$model->data[$model->alias]['width'] = $imgWidth; 
$model->data[$model->alias]['height'] = $imgHeight; 

後,這將增加widthheight到模型的屬性。您應該將widthheight作爲您正在使用的表中的列。

0

端起來後Model::save()呼叫

$image = $this->Event->Image->findById($this->Event->Image->getLastInsertID()); 

$imageDir = new Folder('img/image'); 
$imageFile = new File($imageDir->pwd() . DS . $image['Image']['image_dir'] . DS . $image['Image']['image']); 
list($width, $height) = getimagesize($imageFile->pwd()); 

$this->Event->Image->id = $image['Image']['id']; 
$this->Event->Image->saveField('width', $width); 
$this->Event->Image->saveField('height', $height); 
+0

這樣做,你可以把它放在aftersave http://book.cakephp.org/2.0/en/models/callback-methods.html#aftersave – cornelb 2014-08-29 15:07:55