Hi gud mrng,
i'm new member to the yii.I have one doubt about upload image with resizing option using class.upload files.
In that,I written a code Its working fine but only its working in userModel(user table) if any other model means its won’t work .
My coding in the controller,
userGallary model
public function actionProfileImage($id) {
$userModel = User::model()->findByAttributes(array('id' => $id));
$userGallary = new UserGallary;
$filename = $this->generateUserProfileFileName();
$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->file_new_name_body = $filename;
$handle->process($targetImagePath);
if ($handle->processed) {
$handle->file_name_body_pre = $filePrefix;
$handle->file_new_name_body = $filename;
$handle->image_resize = true; // needs to resize
$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->file_new_name_body = $filename;
$handle->image_resize = true; // needs to resize
$handle->image_x = 25;
$handle->image_y = 25;
// $handle->image_ratio_y = true;
$handle->image_ratio = true;
$handle->process($target25Path);
if ($handle->processed) {
$userGallary->uploaded_picture = "{$filePrefix}{$filename}.{$handle->file_dst_name_ext}";
$userGallary->save(false);
}
}
}
}
$handle->clean();
}
var_dump($userGallary->uploaded_picture);
echo CJSON::encode( arraY('path150' => $target150Path,
'file' => $userGallary->uploaded_picture,
));
}
The value of the file is null.
But the usermodel table:It working fine.the image resize with corresponding folders as well as stored in db
But userGallary table.Only resize the image in corresponding folders not stored in db.
How to store in db.Any one tell me