Ejemplo n.º 1
0
 public function actionDefault($mdl, $pid, $filename)
 {
     $image = new Images();
     if (!($res = $image->bySlug($mdl, $pid, $filename))) {
         throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
     } else {
         return $res;
     }
     return '';
     header('Content-type: image/' . $this->extensions[$info['extension']]);
     header('Content-Length: ' . filesize($info['dstPath']));
     readfile($info['dstPath']);
     exit;
 }
Ejemplo n.º 2
0
 public function actionDeleteimage($id)
 {
     $image = Images::findOne(['id' => $id, 'module' => 'gallery']);
     if ($image) {
         $image->delete();
     }
     if (Yii::$app->request->referrer) {
         return $this->redirect(Yii::$app->request->referrer);
     }
 }
Ejemplo n.º 3
0
 public function run()
 {
     $file = UploadedFile::getInstanceByName($this->fileName);
     if ($file->hasError) {
         throw new HttpException(500, 'Upload error');
     }
     $this->upload = $this->upload . '/' . date('Ym');
     $this->uploadDir = Yii::getAlias('@wwwdir/' . $this->upload . '/');
     $newFileName = \common\components\Utils::fileName(5);
     if (!file_exists($this->uploadDir)) {
         FileHelper::createDirectory($this->uploadDir);
     }
     $fileName = $newFileName . "." . $file->extension;
     if (file_exists($this->uploadDir . $fileName)) {
         $fileName = $newFileName . '-' . uniqid() . '.' . $file->extension;
     }
     $result = $file->saveAs($this->uploadDir . $fileName);
     $response['status'] = 0;
     if ($result) {
         //上传成功";写入数据库
         $item = Yii::$app->request->post('item');
         $item_id = Yii::$app->request->post('item_id');
         $image = new Images();
         $image->item = $item;
         $image->item_id = $item_id;
         $image->filename = $fileName;
         $image->image = "/" . $this->upload . "/" . $fileName;
         $image->filename = $fileName;
         $image->sort_order = 50;
         $n = $image->save();
         if ($n) {
             //$image->
             $response['status'] = 1;
             $response['imgID'] = $image->id;
             $response['filePath'] = "/" . $this->upload . "/" . $fileName;
             $response['initialPreview'] = ["<img src='" . $response['filePath'] . "' class='file-preview-image'>"];
             $response['initialPreviewConfig'] = [['caption' => $fileName, 'width' => "120px;", 'url' => Yii::$app->urlManager->createUrl(['services/remove']), 'key' => $image->id, 'description' => "", 'sort_order' => ""]];
         }
     }
     return Json::encode($response);
 }
Ejemplo n.º 4
0
 public function run()
 {
     $id = Yii::$app->request->post('key');
     // Array or selected records primary keys
     $image = Images::findOne(['id' => $id]);
     if ($image) {
         $filename = $image->image;
         //$thumbname = $image->thumb;
         if (Images::deleteAll(['id' => $id])) {
             if (file_exists(\Yii::getAlias("@wwwdir" . $filename))) {
                 unlink(\Yii::getAlias("@wwwdir" . $filename));
             }
         }
     }
     echo "1";
     //return false;
 }
Ejemplo n.º 5
0
 public function actionIndex()
 {
     $p = intval($this->get("p", 1));
     if (!$p) {
         $p = 1;
     }
     $data = [];
     $pagesize = 20;
     $query = Images::find();
     $total_count = $query->count();
     $offset = ($p - 1) * $pagesize;
     $image_list = $query->orderBy("id desc")->offset($offset)->limit($pagesize)->all();
     $page_info = DataHelper::ipagination(["total_count" => $total_count, "page_size" => $pagesize, "page" => $p, "display" => 10]);
     if ($image_list) {
         $idx = 1;
         foreach ($image_list as $_image_info) {
             $tmp_small_pic_url = GlobalUrlService::buildPicStatic($_image_info['filepath'], ['h' => 100, 'w' => 200], $_image_info['bucket']);
             $tmp_big_pic_url = GlobalUrlService::buildPicStatic($_image_info['filepath'], ['w' => 600], $_image_info['bucket']);
             $data[] = ['idx' => $idx, 'id' => $_image_info['id'], 'small_pic_url' => $tmp_small_pic_url, 'big_pic_url' => $tmp_big_pic_url];
             $idx++;
         }
     }
     return $this->render("index", ["data" => $data, "page_info" => $page_info, "page_url" => "/file/index"]);
 }
Ejemplo n.º 6
0
 public function getImages()
 {
     return $this->hasMany(\common\models\Images::className(), ['parent_id' => 'id'])->where(['module' => 'catalog']);
     //->sort();
 }
Ejemplo n.º 7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getImage()
 {
     return $this->hasOne(Images::className(), ['id' => 'image_id']);
 }
Ejemplo n.º 8
0
 /**
  * 测试封面图片
  *
  * @return \yii\web\Response|\yii\base\string
  */
 public function actionStep1_3($id)
 {
     $this->layout = false;
     $model = Survey::findOne($id);
     // 没有找到
     if (!$model) {
         $model = new Survey();
         if (!$model) {
             return $this->redirect(['my']);
         }
     }
     $this->view->title = $model->title;
     // 图片不存在
     $model_Images = Images::findOne($model->front_img);
     if (!$model_Images) {
         $model_Images = new Images();
         $model_Images->use_count = 0;
     }
     // && !empty($_POST['image'])
     if (isset($_POST['image'])) {
         $load = true;
         // ZCommonFun::print_r_debug($_POST);
         // exit;
         $fileName = $_POST['image'];
         $model_Images->image = $fileName ? $fileName : $model_Images->image;
         // if(empty($model_Images->image)){
         // $model_Images->addError('image','请上传图片');
         // }
         // 设置测试封面
         // 事物开始
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $model->is_publish = 0;
             // 图片保存
             $model_Images->use_count++;
             if (count($model_Images->errors) < 1 && $model_Images->save()) {
                 // 设置测试封面
                 $model->front_img = $model_Images->id;
                 if ($model->save()) {
                     $transaction->commit();
                     switch ($model->tax) {
                         // 奇趣测试
                         case 1:
                             // 跳转到添加测试结果
                             return $this->redirect(['step4_2', 'id' => $model->id]);
                             break;
                             // 分数型心里测试
                         // 分数型心里测试
                         case 2:
                             return $this->redirect(['step4_2_question', 'id' => $model->id]);
                             break;
                             // 跳转型心里测试
                         // 跳转型心里测试
                         case 3:
                             return $this->redirect(['step4_2_question', 'id' => $model->id]);
                             break;
                         default:
                             break;
                     }
                 }
             }
         } catch (\Exception $e) {
             $transaction->rollBack();
         }
         // ZCommonFun::print_r_debug($arr);
         // exit;
     }
     // ZCommonFun::print_r_debug($model_Images);
     return $this->render('step1_3', ['model_Images' => $model_Images, 'tax' => $model->tax, 'model' => $model]);
 }
Ejemplo n.º 9
0
 public function getImages()
 {
     return $this->hasOne(Images::className(), ['id' => 'front_img']);
 }
Ejemplo n.º 10
0
 public function getImages()
 {
     return $this->hasMany(Images::className(), ['id' => 'object_id'])->via('imagesOfObjects');
 }
Ejemplo n.º 11
0
 private function listUeditorImage()
 {
     $start = intval($this->get("start", 0));
     $page_size = intval($this->get("size", 20));
     $query = Images::find()->where(['bucket' => "pic1"]);
     if ($start) {
         $query->andWhere(['<', "id", $start]);
     }
     $list = $query->orderBy("id desc")->limit($page_size)->all();
     $images = [];
     $last_id = 0;
     if ($list) {
         foreach ($list as $_item) {
             $images[] = ['url' => GlobalUrlService::buildPic1Static($_item['filepath'], ['w' => 600]), 'mtime' => strtotime($_item['created_time']), 'width' => 300];
             $last_id = $_item['id'];
         }
     }
     header('Content-type: application/json');
     $data = ["state" => count($images) > 0 ? 'SUCCESS' : 'no match file', "list" => $images, "start" => $last_id, "total" => count($images)];
     echo json_encode($data);
     exit;
 }
Ejemplo n.º 12
0
 public function deleteImage()
 {
     /* @var $modelImages \common\models\Images */
     /* @var $modelImagesOfObject \common\models\ImagesOfObject */
     $paramsImageDeleteData = Json::decode($this->imageData);
     $modelImages = Images::findOne($paramsImageDeleteData['image_id']);
     //d([$paramsImageDeleteData]);
     $modelImagesOfObject = ImagesOfObject::findOne(['image_id' => $paramsImageDeleteData['image_id'], 'object_id' => $paramsImageDeleteData['object_id']]);
     //dd($modelImagesOfObject);
     $transaction = Yii::$app->db->beginTransaction();
     try {
         if ($modelImagesOfObject->delete()) {
             if ($modelImages->delete()) {
                 if ($this->deleteImageFile($modelImages->path) && $this->deleteImageFile($modelImages->path_small_image)) {
                     $transaction->commit();
                 }
             }
         }
     } catch (Exception $e) {
         $transaction->rollBack();
     }
 }
Ejemplo n.º 13
0
 public static function checkHashKey($hash_key)
 {
     return Images::findOne(['hash_key' => $hash_key]);
 }