Exemple #1
0
 /**
  * <Jason>
  * <Email: pmhai90@gmail.com>
  */
 public static function saveImage($model)
 {
     if (is_null($model->imageFile)) {
         return '';
     }
     $ext = $model->imageFile->getExtensionName();
     $fileName = time() . '.' . $ext;
     $imageProcessing = new ImageProcessing();
     $imageProcessing->createDirectoryByPath('/upload/admin/' . self::$folderUpload . '/' . $model->id);
     $model->imageFile->saveAs('upload/admin/' . self::$folderUpload . '/' . $model->id . '/' . $fileName);
     return $fileName;
 }
 /**
  * Jun 07, 2014 - ANH DUNG
  * To do: save file 
  * @param: $model is model ProGlobalEnquiry
  * @param: $fieldName file_name
  * @return: name of image upload/global_enquiry
  */
 public static function saveFile($model, $fieldName)
 {
     if (is_null($model->{$fieldName})) {
         return '';
     }
     $aDate = explode('-', $model->date_only);
     $pathUpload = ProGlobalEnquiry::$folderUpload . "/{$aDate['0']}/{$aDate['1']}/{$aDate['2']}";
     $ext = $model->{$fieldName}->getExtensionName();
     $file_name_slug = strtolower(MyFunctionCustom::slugify($model->{$fieldName}->getName()));
     $file_name_slug = str_replace(strtolower($ext), '', $file_name_slug);
     $model->file_name_slug = $file_name_slug;
     $fileName = date('Y-m-d');
     $fileName = time() . '-' . ActiveRecord::randString() . '.' . $ext;
     $imageProcessing = new ImageProcessing();
     $imageProcessing->createDirectoryByPath($pathUpload);
     $model->{$fieldName}->saveAs($pathUpload . '/' . $fileName);
     $model->{$fieldName} = $fileName;
     return $fileName;
 }
Exemple #3
0
 /**
  * @Author: ANH DUNG Aug 12, 2014
  * To do: save file 
  * @param: $model 
  * @param: $fieldName 
  * @param: $count 1,2,3
  */
 public static function saveFile($model, $fieldName, $fileName)
 {
     if (is_null($model->{$fieldName})) {
         return '';
     }
     $pathUpload = ProListingPhotos::$folderUpload . "/{$model->listing_id}";
     $ext = $model->{$fieldName}->getExtensionName();
     $imageProcessing = new ImageProcessing();
     $imageProcessing->createDirectoryByPath($pathUpload);
     $model->{$fieldName}->saveAs($pathUpload . '/' . $fileName);
     $model->{$fieldName}->saveAs($pathUpload . '/' . ProListingPhotos::SIZE_WATER_MARK . $fileName);
     //        return $fileName;
 }
 /**
  * Jun 07, 2014 - ANH DUNG
  * To do: save file 
  * @param: $model is model ProGlobalEnquiry
  * @param: $fieldName file_name
  * @return: name of image upload/global_enquiry
  */
 public static function saveFile($model, $fieldName)
 {
     if (is_null($model->{$fieldName})) {
         return '';
     }
     $pathUpload = ProInventoryPhoto::$folderUpload;
     $ext = $model->{$fieldName}->getExtensionName();
     $file_name_slug = strtolower(MyFunctionCustom::slugify($model->{$fieldName}->getName()));
     $file_name_slug = str_replace(strtolower($ext), '', $file_name_slug);
     $model->file_name_slug = $file_name_slug;
     $fileName = date('Y-m-d');
     $uid = isset(Yii::app()->user->id) ? Yii::app()->user->id : 999999;
     $fileName = $uid . '-' . time() . '-' . ActiveRecord::randString() . '.' . $ext;
     $imageProcessing = new ImageProcessing();
     $imageProcessing->createDirectoryByPath($pathUpload);
     $model->{$fieldName}->saveAs($pathUpload . '/' . $fileName);
     $model->{$fieldName} = $fileName;
     return $fileName;
 }
 /**
  * Apr 01, 2014 - ANH DUNG
  * To do: save file 
  * @param: $model transactions
  * @param: $nameField ex: file_name
  * @param: $pathUpload ex: 'upload/transactions/property_document';  
  * @param: $nameBase name to show if need (option)
  * public static $folderUpload='upload/products/';
  * @return: name of image
  */
 public static function saveFile($model, $nameField, $pathUpload, $count)
 {
     if (is_null($model->{$nameField})) {
         return '';
     }
     $ext = $model->{$nameField}->getExtensionName();
     //        $nameBase = $model->$nameField->getName();
     //        $nameBase = str_replace(strtolower($ext), '', $nameBase);
     //        $nameBase = str_replace(strtoupper($ext), '', $nameBase);
     //        $nameBase = trim($nameBase, '.');
     $fileName = MyFunctionCustom::slugify($model->{$nameField}->getName());
     $fileName = str_replace(strtolower($ext), '', $fileName);
     $fileName = trim($fileName, '-');
     $fileName = trim($fileName);
     //        $fileName = time().'_'.$fileName.'.'.$ext;
     $fileName = $fileName . '-' . time() . $count . '.' . $ext;
     //        $fileName = $fileName.'.'.$ext;
     $imageProcessing = new ImageProcessing();
     $imageProcessing->createDirectoryByPath($pathUpload . '/' . $model->transactions_id);
     $model->{$nameField}->saveAs($pathUpload . '/' . $model->transactions_id . '/' . $fileName);
     return $fileName;
 }
Exemple #6
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     try {
         $model = Pages::model()->findbyPk($id);
         $model->scenario = 'update';
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         $old_image = $model->featured_image;
         $old_home_page = $model->thumb_image;
         if (isset($_POST['Pages'])) {
             $oldImg = $model->banner;
             $model->attributes = $_POST['Pages'];
             $uploadFile = CUploadedFile::getInstance($model, 'banner');
             $model->parent_id = $_POST['Pages']['parent_id'];
             //                $model->show_footer = $_POST['Pages']['show_footer'];
             //                $model->show_home_page = $_POST['Pages']['show_home_page'];
             //                $model->short_content = $_POST['Pages']['short_content'];
             //                $model->order = $_POST['Pages']['order'];
             if (isset($_POST['ck'])) {
                 $model->show_desc = 1;
             } else {
                 $model->show_desc = 0;
             }
             $isEmptyFileInput = empty($_FILES["Pages"]["name"]["imageFile"]);
             $new_banner = '';
             if (!$isEmptyFileInput) {
                 //has file input
                 $model->imageFile = CUploadedFile::getInstance($model, 'imageFile');
             }
             $isEmptyHomePageInput = empty($_FILES["Pages"]["name"]["thumbFile"]);
             $new_home_page = '';
             if (!$isEmptyHomePageInput) {
                 //has file input
                 $model->thumbFile = CUploadedFile::getInstance($model, 'thumbFile');
             }
             if ($model->validate()) {
                 if ($uploadFile) {
                     // remove old image and save new image to disk
                     $model->removeBanner($oldImg);
                     $model->saveBanner($uploadFile);
                 } else {
                     $model->banner = $oldImg;
                     // keep old image
                 }
                 if (!$isEmptyFileInput) {
                     //has file input
                     $errorBanner = false;
                     if (MyFunctionCustom::bannerIsSmall($model->imageFile->getTempName(), Pages::$aSizeBanner['960x252']['width'], Pages::$aSizeBanner['960x252']['height'])) {
                         $errorBanner = true;
                     }
                     //Checked size of banner
                     if ($errorBanner) {
                         $model->addError('imageFile', 'Banner file size need larger than 960x252.');
                     } else {
                         $ext_banner = $model->imageFile->getExtensionName();
                         $timestamp_banner = time();
                         $new_banner = $timestamp_banner . '.' . $ext_banner;
                     }
                 }
                 if (!$isEmptyHomePageInput) {
                     //has file input
                     //Checked size of banner
                     $errorBanner = false;
                     if (MyFunctionCustom::bannerEqual($model->thumbFile->getTempName(), Pages::$aSizeHomePage['204x94']['width'], Pages::$aSizeHomePage['204x94']['height'])) {
                         $errorBanner = true;
                     }
                     //Checked size of banner
                     if ($errorBanner) {
                         $model->addError('thumbFile', 'Thumb file size must be equal 204x94.');
                     } else {
                         $ext_home_page = $model->thumbFile->getExtensionName();
                         $timestamp_home_page = time();
                         $model->thumb_image = $timestamp_home_page . '.' . $ext_home_page;
                     }
                 }
                 if (!$model->hasErrors()) {
                     if (isset($_POST['delete_current_image']) && $_POST['delete_current_image'] == 'on') {
                         Pages::deleteImage($model);
                         $model->featured_image = NULL;
                         if (!$isEmptyFileInput) {
                             $ImageProcessing = new ImageProcessing();
                             $ImageProcessing->delete('upload/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $old_image);
                             $ImageProcessing->createDirectoryByPath('upload/admin/' . Pages::$folderUpload . '/' . $model->id);
                             $model->imageFile->saveAs(YII_UPLOAD_DIR . '/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $new_banner);
                             $model->featured_image = $new_banner;
                             $model->resizeBanner();
                         }
                         $model->update();
                     } else {
                         if ($new_banner != NULL) {
                             $model->featured_image = $new_banner;
                         }
                         if ($model->update()) {
                             if (!$isEmptyFileInput) {
                                 $ImageProcessing = new ImageProcessing();
                                 $ImageProcessing->delete('upload/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $old_image);
                                 $ImageProcessing->createDirectoryByPath('upload/admin/' . Pages::$folderUpload . '/' . $model->id);
                                 $model->imageFile->saveAs(YII_UPLOAD_DIR . '/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $model->featured_image);
                                 $model->resizeBanner();
                             }
                         }
                     }
                     //For home page
                     if (isset($_POST['delete_current_image_home_page']) && $_POST['delete_current_image_home_page'] == 'on') {
                         Pages::deleteImage($model, true);
                         $model->thumb_image = NULL;
                         if (!$isEmptyHomePageInput) {
                             $ImageProcessing = new ImageProcessing();
                             $ImageProcessing->delete('upload/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $old_home_page);
                             $ImageProcessing->createDirectoryByPath('upload/admin/' . Pages::$folderUpload . '/' . $model->id);
                             $model->thumbFile->saveAs(YII_UPLOAD_DIR . '/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $new_home_page);
                             $model->thumb_image = $new_home_page;
                             $model->resizeHomePages();
                         }
                         $model->update();
                     } else {
                         if ($new_home_page != NULL) {
                             $model->thumb_image = $new_home_page;
                         }
                         if ($model->update()) {
                             if (!$isEmptyHomePageInput) {
                                 $ImageProcessing = new ImageProcessing();
                                 $ImageProcessing->delete('upload/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $old_home_page);
                                 $ImageProcessing->createDirectoryByPath('upload/admin/' . Pages::$folderUpload . '/' . $model->id);
                                 $model->thumbFile->saveAs(YII_UPLOAD_DIR . '/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $model->thumb_image);
                                 $model->resizeHomePages();
                             }
                         }
                     }
                     $this->redirect(array('view', 'id' => $model->id));
                 }
             }
         }
         $this->render('update', array('model' => $model, 'actions' => $this->listActionsCanAccess));
     } catch (exception $e) {
         Yii::log("Exception " . print_r($e, true), 'error');
         throw new CHttpException("Exception " . print_r($e, true));
     }
 }