コード例 #1
0
 public function actionCreate()
 {
     $id = intval($_GET['id']);
     if (!$id) {
         exit('error 1');
     }
     $dir = Yii::app()->params['uploadPathImage'] . 'gallery/' . $id;
     $upload = CUploadedFile::getInstanceByName('Filedata');
     if ($upload->getSize()) {
         $model = new GalleryImage();
         $model->gallery_id = $id;
         $model->save();
         if (!file_exists($dir)) {
             mkdir($dir, 0777, true);
         }
         $bigFile = $dir . '/' . $model->id . '_origin.' . $upload->getExtensionName();
         $smallFile = $dir . '/' . $model->id . '.' . $upload->getExtensionName();
         $upload->saveAs($bigFile);
         // 压缩文件
         $image = Yii::app()->image->load($bigFile);
         $image->resize(Yii::app()->params['uploadMaxWidth'], Yii::app()->params['uploadMaxHeight'])->quality(Yii::app()->params['uploadQuality']);
         $image->save($smallFile);
         $model->file = $id . '/' . $model->id . '.' . $upload->getExtensionName();
         $model->save();
         echo json_encode(['id' => $model->id, 'file' => $model->file]);
     } else {
         exit('error 2');
     }
 }
コード例 #2
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aGalleryImage !== null) {
             if ($this->aGalleryImage->isModified() || $this->aGalleryImage->isNew()) {
                 $affectedRows += $this->aGalleryImage->save($con);
             }
             $this->setGalleryImage($this->aGalleryImage);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
コード例 #3
0
ファイル: Controller.php プロジェクト: radicaldesigns/amp
 function _save_galleryInfo($data)
 {
     if (!(isset($data['galleryid']) && !empty($data['galleryid']))) {
         return false;
     }
     require_once 'Modules/Gallery/Image.inc.php';
     $galleries = is_array($data['galleryid']) ? array_keys($data['galleryid']) : array($data['galleryid']);
     foreach ($galleries as $gallery_id) {
         $gallery_image = new GalleryImage(AMP_Registry::getDbcon());
         $data['galleryid'] = $gallery_id;
         $gallery_image->setData($data);
         $gallery_image->save();
     }
 }
コード例 #4
0
ファイル: Image.php プロジェクト: radicaldesigns/amp
 function gallery($gallery_id)
 {
     require_once 'Modules/Gallery/Image.inc.php';
     $image_record = new GalleryImage(AMP_Registry::getDbcon());
     $image_record->setGallery($gallery_id);
     $image_record->setImageFileName($this->getName());
     $image_record->publish();
     $image_record->setItemDate(date('Y-m-d', $this->getTime()));
     $db_metadata = $this->getData();
     unset($db_metadata['id']);
     $image_record->mergeData($db_metadata);
     $result = $image_record->save();
     $this->notify('update');
     $this->notify('gallery');
     AMP_lookup_clear_cached('galleries_by_image', $this->getName());
     return $result;
 }
コード例 #5
0
ファイル: Form.inc.php プロジェクト: radicaldesigns/amp
 function _checkUploadImage($data, $fieldname)
 {
     if (!(isset($data['image_upload']) && $data['image_upload'])) {
         if (!isset($data[$fieldname])) {
             return false;
         }
         return $data[$fieldname];
     }
     if (!(isset($data['image_gallery']) && $data['image_gallery'])) {
         return $data['image_upload'];
     }
     require_once 'Modules/Gallery/Image.inc.php';
     $gallery_record = new GalleryImage(AMP_Registry::getDbcon());
     $gallery_data = array('img' => $data['image_upload'], 'caption' => isset($data['piccap']) ? $data['piccap'] : false, 'galleryid' => $data['image_gallery'], 'section' => $data['section'], 'publish' => true, 'date' => date('Y-m-d'));
     $gallery_record->setData($gallery_data);
     $gallery_record->save();
     return $data['image_upload'];
 }