/** * Add new images * * @param array $data * @return boolean true on succes, or false on fail */ function add($data) { $sm = vivvo_lite_site::get_instance(); if ($sm->user) { if ($sm->user->can('MANAGE_PLUGIN', 'image_gallery')) { $article_images_list = new ArticleImages_list(); $new_order_num = $article_images_list->get_max('order_number'); if ($new_order_num) { $new_order_num = $new_order_num + 1; } else { $new_order_num = 1; } foreach ($data as $key) { $article_images = new ArticleImages(); $key['order_number'] = $new_order_num; $new_order_num++; if ($article_images->populate($key, true) === false) { return false; } $this->_post_master->set_data_object($article_images); if (!$this->_post_master->sql_insert()) { $this->set_error_code(11201); return false; } } return true; } else { $this->set_error_code(11202); return false; } } else { $this->set_error_code(11203); return false; } }
public function addDropboxFiles($uploadsession) { $files = $this->tmpFiles; // $existFiles = count($this->images); // $availableFiles = $this->maxFiles - $existFiles; $cnt = 0; // if($files){ if(Yii::app()->session->itemAt($uploadsession)){ // $folder='uploads'. DIRECTORY_SEPARATOR .'tmp'. DIRECTORY_SEPARATOR; $folder = Yii::getPathOfAlias(Yii::app()->params['storeImages']['tmp']).DIRECTORY_SEPARATOR; $dataSession = Yii::app()->session->itemAt($uploadsession); // foreach($files as $fileUploadName){ if(is_array($dataSession)){ foreach($dataSession as $key => $value){ // if($fileUploadName == $key){ if(@file_exists($folder.$value )) { //if($cnt >= $availableFiles) // break 2; /* $file = $folder.$value; $ext = pathinfo($folder.$value, PATHINFO_EXTENSION); $base = md5(rand(1000,4000)); $unique = $base.'_article'; $suffix = 1; while (file_exists($this->getFileFolder() . $unique . $ext)){ $unique = $base.'_'.$suffix; $suffix++; } $filename = $unique . '.' . $ext; $fullPath = $this->getFileFolder() . $filename;*/ $fullPath = $this->getFileFolder().$value; if (copy($folder.$value, $fullPath)) { unlink($folder.$value); $image = new ArticleImages(); $image->article = $this->getPrimaryKey(); $image->filename = $value; $image->realname = $key; /* Yii::import('ext.phpthumb.PhpThumbFactory'); $thumb = PhpThumbFactory::create($fullPath); $thumb->setOptions(array('jpegQuality'=>100)); $thumb->resize(1000)->save($fullPath); */ $image->save(); $cnt++; } else { // throw new CHttpException(404, Yii::t('Site', 'Cannot copy file to folder.')); } } // } } } // } } // } }
public function actionDeleteFile($id) { $id = (int)$id; // check that you have access to this note $file = ArticleImages::model()->findByPk($id); if(isset($file->organization)){ // $pin = $this->_loadModel($file->pinboard->id); // remove it from disk also in model issueFile if($file->delete()) { echo "[]"; Yii::app()->end(); } } echo 'error'; Yii::app()->end(); }