public static function getImageById($id) { $criteria = new CDbCriteria(); $criteria->select = "image_path, image_title, image_ext"; $criteria->condition = "id=:id"; $criteria->params = array(':id' => (int) $id); /* $connection = Yii::app()->db; $sql = "SELECT image_path, image_title, image_ext FROM {{images}} WHERE id = ".$id; $command = $connection->createCommand($sql); $rs = $command->queryRow(); */ $rs = AImages::model()->find($criteria); if ($rs) { return "<img src='" . Yii::app()->params->upload_path . $rs['image_path'] . $rs['image_title'] . "_110." . $rs['image_ext'] . "'/>"; } else { return false; } }
public function actionUpload() { if (isset($_FILES['files']) && $_FILES['files']) { require Yii::app()->basePath . '/components/upload.class.php'; $handle = new upload($_FILES['files']); $img_arr = array(); $file_info = AFunction::generate_file_name('news'); $_filename = $file_info['name']; $_filepath = realpath(Yii::app()->getBasePath() . '/../uploads/') . "/" . $file_info['physical_path']; if ($handle->uploaded) { //check extension if (!in_array($handle->file_src_name_ext, array('gif', 'jpg', 'jpeg', 'pjpeg'))) { //$this->error->add('ERROR_UPLOAD', $this->language->getMsg('YOU_CAN_UPLOAD_WITH_FILE_EXTENSION_JPG_JPEG_PJPEG')); return false; } $handle->file_new_name_body = $_filename; $handle->process($_filepath); if ($handle->processed) { require Yii::app()->basePath . '/components/byte_converter.class.php'; $byte = new byte_converter(); $byte->set_limit("mb"); $img_arr['id'] = 0; $img_arr['image_title'] = $_filename; $img_arr['image_ext'] = $handle->file_src_name_ext; $img_arr['image_path'] = $file_info['physical_path']; $img_arr['image_mime_type'] = $handle->image_src_type; $img_arr['image_width'] = $handle->image_src_x; $img_arr['image_height'] = $handle->image_src_y; $img_arr['image_size'] = $handle->file_src_size; $modelImage = new AImages(); $modelImage->image_title = $img_arr['image_title']; $modelImage->image_ext = $img_arr['image_ext']; $modelImage->image_path = $img_arr['image_path']; $modelImage->image_mime_type = $img_arr['image_mime_type']; $modelImage->image_width = $img_arr['image_width']; $modelImage->image_height = $img_arr['image_height']; $modelImage->image_size = $img_arr['image_size']; if ($modelImage->save()) { $img_arr['id'] = $modelImage->id; } } //upload width thumbnail 110 $handle->file_new_name_body = $_filename . '_' . Yii::app()->params->width110; $handle->image_resize = true; $handle->image_x = Yii::app()->params->width110; $handle->image_ratio_y = true; $handle->process($_filepath); if ($handle->processed) { $handle->Clean(); } echo json_encode($img_arr); exit; } else { echo json_encode(array('Upload Fail !')); exit; } } else { echo json_encode(array('Can not upload file !')); exit; } }
<?php $this->breadcrumbs = array(Yii::t('adm/news', 'manage_news') => array('admin'), $model->id); $this->menu = array(array('label' => Yii::t('adm/app', 'create_sysuser'), 'url' => array('create'), 'linkOptions' => array('class' => 'link-new')), array('label' => Yii::t('adm/app', 'update_sysuser'), 'url' => array('update', 'id' => $model->id), 'linkOptions' => array('class' => 'link-edit')), array('label' => Yii::t('adm/app', 'delete_sysuser'), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => Yii::t('adm/app', 'confirm'), 'class' => 'link-delete')), array('label' => Yii::t('adm/app', 'icon_sysuser'), 'url' => array('admin'), 'linkOptions' => array('class' => 'link-manageuser'))); ?> <h3><?php echo Yii::t('adm/news', 'view_news'); ?> <?php echo $model->news_title; ?> </h3> <?php $this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', 'news_category_id', 'news_title', 'news_short_description:html', 'news_detail:html', 'status', 'priority', 'created_time', 'created_by', 'updated_time', 'updated_by', array("name" => 'image_id', 'type' => 'html', "value" => AImages::getImageById($model->image_id)))));