如何在db中保存数据

时间:2013-12-12 06:20:43

标签: yii image-uploading

在用户表中,存储在db中的数据以及调整文件夹中的图像大小。 但是usergallary表相同的功能只能在文件夹中调整大小但不存储在db中的图像。

public function actionProfileImage($id) {
    $userModel = User::model()->findByAttributes(array('id' => $id));
    $userGallary = new UserGallary;
            $filePrefix = Yii::app()->params['profile']['prefix'];
            $targetImagePath = Yii::app()->params['profile']['image']['path'];
            $target150Path = Yii::app()->params['profile']['thumb150']['path'];
            $target25Path = Yii::app()->params['profile']['thumb25']['path'];
            if (isset($_FILES['uploaded_picture'])) {
                $handle = new Upload($_FILES['uploaded_picture']);
                if ($handle->uploaded) {
                    $handle->file_name_body_pre   = $filePrefix;
                    $handle->process($targetImagePath);
                    if ($handle->processed) {
                        $handle->file_name_body_pre   = $filePrefix;
                        $handle->image_resize         = true;                    
                        $handle->image_x              = 150;
                        $handle->image_y              = 150;
                        //$handle->image_ratio_y        = true;
                        $handle->image_ratio           = true;
                        $handle->process($target150Path);
                            if ($handle->processed) {
                            $handle->file_name_body_pre   = $filePrefix;
                            $handle->image_resize        = true;                    
                            $handle->image_x              = 25;
                            $handle->image_y              = 25;
                           // $handle->image_ratio_y        = true;
                            $handle->image_ratio           = true;
                            var_dump($$target150Path);exit;
                            $handle->process($target25Path);
                                if ($handle->processed) {
                                    $userGallary->uploaded_picture = "{$filePrefix}.{$handle->file_dst_name_ext}";
                                    $userGallary->save();
                            }
                  }
                $handle->clean();
            }
            }
            }
            echo CJSON::encode( arraY('path150' => $target150Path,
                                       'file'    =>  $userGallary->uploaded_picture,
                                                                ));



}

0 个答案:

没有答案