Exemple #1
1
 function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $file = UploadedFile::getInstance($this, 'image');
         if ($file && $file->error === UPLOAD_ERR_OK) {
             // Ищем, есть ли уже такой загруженный файл
             $file_model = Files::findOne(['hash' => md5_file($file->tempName)]);
             if ($file_model) {
                 $file_model->repeats++;
             } else {
                 $file_model = new Files();
                 $file_model->saveImageFile($file);
                 $file_model->repeats = 1;
             }
             $file_model->save();
             $this->file_id = $file_model->id;
         } else {
             $this->addError('image', 'Невозможно загрузить файл');
             return false;
         }
         return true;
     } else {
         return false;
     }
 }
 /**
  * Uploads files to user's directory
  * @return string exception message if error
  * @throws GoodException if data not saved to DB
  */
 protected function uploadFiles()
 {
     try {
         $modelUpload = new UploadForm();
         $modelUpload->file = UploadedFile::getInstances($modelUpload, 'file');
         if ($modelUpload->file && $modelUpload->validate()) {
             foreach ($modelUpload->file as $file) {
                 $pathToFile = '../upload/' . Yii::$app->user->identity['login'] . '/' . $file->baseName . '.' . $file->extension;
                 if (Yii::$app->params['userWorkSpace'] - self::getUsersFilesSize('mb') < self::toMb($file->size)) {
                     throw new GoodException('Limited workspace', 'Please delete some your files for successfuly upload this file...');
                 }
                 if (!$file->saveAs($pathToFile)) {
                     throw new GoodException('Error', 'Can\'t save file...');
                 }
                 if (Files::find()->where(['path' => $file->baseName . '.' . $file->extension, 'id_user' => Yii::$app->user->identity->id])->one()) {
                     continue;
                 }
                 $modelFiles = new Files();
                 $modelFiles->id_user = Yii::$app->user->identity['id'];
                 $modelFiles->path = $file->baseName . '.' . $file->extension;
                 $modelFiles->share_link = Yii::$app->security->generateRandomString();
                 $modelFiles->size = self::toKb($file->size);
                 if (!$modelFiles->save()) {
                     unlink($pathToFile);
                     throw new GoodException('Error', 'Save data error...');
                 }
                 $this->goHome();
             }
         }
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
Exemple #3
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->file->error === UPLOAD_ERR_OK) {
             // die('before2');
             try {
                 $filename = 'uploads/' . uniqid() . '.' . $this->file->extension;
                 $this->file->saveAs($filename);
                 // Если связанное изображение уже существует, просто изменяем его
                 if ($file_model = $this->getImage()->one()) {
                 } else {
                     $file_model = new Files();
                 }
                 $file_model->filename = $filename;
                 $file_model->size = $this->file->size;
                 $file_model->post_id = $this->id;
                 $thumb_filename = 'uploads/thumbs/' . uniqid() . '.' . $this->file->extension;
                 Image::thumbnail($filename, 100, 100)->save($thumb_filename, ['quality' => 90]);
                 $file_model->thumb_filename = $thumb_filename;
                 $file_model->save();
                 $this->image_id = $file_model->id;
             } catch (\Exception $e) {
                 $this->addError('file', 'Ошибка загрузки файла');
                 return false;
             }
         }
         return true;
     } else {
         return false;
     }
 }
Exemple #4
0
 public function actionIndex($id, $tagId = null)
 {
     $project = $this->loadModel('app\\models\\Project', $id);
     $this->view->params['appSettings'] = ['app_name' => $project->title];
     if (!\Yii::$app->user->can('viewProject', ['project' => $project])) {
         throw new ForbiddenHttpException('Access denied');
     }
     $model = new Files();
     if (($files = UploadedFile::getInstances($model, 'file')) && !\Yii::$app->user->isGuest) {
         foreach ($files as $file) {
             $model = new Files();
             $model->file = $file->name;
             $model->project_id = $project->id;
             $model->tags = $_POST['Files']['tags'];
             if ($model->save()) {
                 $file->saveAs($this->_getFolder($model) . $file->name);
             } else {
                 die(var_dump($file->getErrors()));
             }
         }
     }
     $searchModel = new FilesSearch();
     $searchModel->project_id = (int) $project->id;
     if (isset($tagId)) {
         $searchModel->tagId = $tagId;
     }
     $dataProvider = $searchModel->search(\Yii::$app->request->queryParams);
     $model->tags = null;
     return $this->render('index', ['model' => $model, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'project' => $project, 'tagId' => $tagId]);
 }
Exemple #5
0
 /**
  * Creates a new Files model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Files();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id, 'user_id' => $model->user_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemple #6
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Files();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     return $this->render('create', array('model' => $model));
 }
Exemple #7
0
 /**
  * Сохраняет загруженный файл и создает ссылки в бд.
  * @param $attribute
  * @return bool
  */
 function saveUploadedImage($attribute)
 {
     $file = UploadedFile::getInstance($this, $attribute);
     if ($file->error === UPLOAD_ERR_OK) {
         $file_model = new Files();
         $file_model->saveImageFile($file);
         $file_model->post_id = $this->post_id;
         $file_model->save();
         $this->image_id = $file_model->id;
         return true;
     }
     return false;
 }
Exemple #8
0
 public function upload()
 {
     // привет                                     Inflector::slug(pathinfo($file->name, PATHINFO_FILENAME))
     if ($this->validate()) {
         //$this->imageFile->saveAs('uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
         //$this->imageFile->saveAs('uploads/' . mb_convert_encoding($this->imageFile->baseName, "Windows-1251", "UTF-8" ) . '.' . $this->imageFile->extension);
         $new_file_name = md5($this->imageFile->baseName . time()) . '.' . $this->imageFile->extension;
         $this->imageFile->saveAs('uploads/' . $new_file_name);
         $file = new Files();
         $file->filename = $new_file_name;
         $file->title = $this->imageFile->baseName . '.' . $this->imageFile->extension;
         $file->save();
         return true;
     } else {
         return false;
     }
 }
Exemple #9
0
 public function save($runValidation = true, $attributes = NULL)
 {
     $class = get_class($this);
     if ($class == 'Accounts') {
         if (Accounts::findOne($this->id)) {
             $this->isNewRecord = false;
         }
     }
     $a = parent::save($runValidation, $attributes);
     if ($a) {
         //if (isset($_POST['Files'])) {
         //$this->attributes = $_POST['Files'];
         $tmps = \yii\web\UploadedFile::getInstancesByName('Files');
         // proceed if the images have been set
         if (isset($tmps) && count($tmps) > 0) {
             \Yii::info('saved');
             // go through each uploaded image
             $configPath = \app\helpers\Linet3Helper::getSetting("company.path");
             foreach ($tmps as $image => $pic) {
                 $img_add = new Files();
                 $img_add->name = $pic->name;
                 //it might be $img_add->name for you, filename is just what I chose to call it in my model
                 $img_add->path = "files/";
                 $img_add->parent_type = get_class($this);
                 $img_add->parent_id = $this->id;
                 // this links your picture model to the main model (like your user, or profile model)
                 $img_add->save();
                 // DONE
                 if ($pic->saveAs($img_add->getFullFilePath())) {
                     // add it to the main model now
                 } else {
                     echo 'Cannot upload!';
                 }
             }
             if (isset($_FILES)) {
                 Yii::info(print_r($_FILES, true));
                 unset($_FILES);
                 $tmps = \yii\web\UploadedFile::reset();
             }
             //}
         }
     }
     //endFile
     return $a;
 }
Exemple #10
0
 /**
  * Creates a new Files model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Files();
     if ($model->load(Yii::$app->request->post())) {
         // process uploaded image file instance
         $file = $model->uploadImage();
         if ($model->save()) {
             // upload only if valid uploaded file instance found
             if ($file !== false) {
                 $path = $model->getImageFile();
                 $file->saveAs($path);
             }
             Yii::$app->session->setFlash("file-success", '<i class="fa fa-check"></i> Arquivo anexado com sucesso!');
             return $this->redirect(['/solicitation/view', 'id' => $model->solicitation_id, '#' => 'checklist']);
         } else {
             // error in saving model
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Exemple #11
0
 public function upload()
 {
     if ($this->validate()) {
         $path = $this->getStoreInfo();
         $store_to = $path['real'] . $path['route'];
         if (!file_exists($store_to)) {
             FileHelper::createDirectory($store_to);
         }
         foreach ($this->files as $f) {
             $image = $this->isImageFile($f);
             $new_fn = $this->newFileName($f->baseName, $f->extension, $image);
             if ($f->saveAs($store_to . $new_fn)) {
                 $model = new Files();
                 if ($image) {
                     $model->attachBehavior('imageFileBehavior', ['class' => ImageBehavior::className()]);
                 }
                 $model->filename = $new_fn;
                 $model->base_dir = $path['real'];
                 $model->base_url = $path['web'];
                 $model->path = $path['route'];
                 $model->title = $f->baseName;
                 $model->alias = str_replace('.' . $f->extension, '', $new_fn);
                 $model->attach_table = $this->tableId;
                 $model->attach_id = $this->id;
                 if ($model->save()) {
                     $this->_uploadedIds[] = $model->id;
                 }
                 $this->_fn = $new_fn;
                 $this->_url = $path['web'] . $path['route'] . $new_fn;
             }
             //TODO обработка ошибки сохранения файла
         }
         return true;
     }
     return false;
 }
Exemple #12
0
 public static function pdfDoc($model)
 {
     $yiiBasepath = Yii::$app->basePath;
     $yiiUser = \app\helpers\Linet3Helper::getUserId();
     //$configPath = app\helpers\Linet3Helper::getSetting("company.path");
     $user = User::findOne($yiiUser);
     if (!$user->hasCert()) {
         //create new
         $settings = array('commonName' => $user->username, 'emailAddress' => $user->email);
         if (\app\helpers\Linet3Helper::getSetting('company.en.city') != '') {
             $settings['localityName'] = \app\helpers\Linet3Helper::getSetting('company.en.city');
         }
         if (\app\helpers\Linet3Helper::getSetting('company.en.name') != '') {
             $settings['organizationName'] = \app\helpers\Linet3Helper::getSetting('company.en.name');
         }
         $ssl = new \app\helpers\SSLHelper($settings);
         $filename = $user->getCertFilePath();
         \app\helpers\Linet3Helper::setSetting('company.' . $yiiUser . '.certpasswd', $ssl->createUserCert($filename));
         //$user->save();
     }
     $configCertpasswd = \app\helpers\Linet3Helper::getSetting('company.' . $yiiUser . '.certpasswd');
     $name = $model->docType->name . "-" . "{$model->docnum}.pdf";
     $file = PrintDoc::findFile($model, $name);
     if (!$file) {
         $model->preview = 2;
         $docfile = PrintDoc::printMe($model);
         /*//adam
           $file = new Files();
           $file->name = $name;
           $file->path = "docs/";
           $file->parent_type = get_class($model);
           $file->parent_id = $model->id;
           $file->hidden = 1;
           $file->public = 0;
           $file->save();
           $file->writeFile($docfile);
           exit;
           //adam*/
         //$mPDF1 = new Pdf;
         //$mPDF1->execute(['WriteHTML' => $docfile]);
         $pdf = new Pdf(['mode' => Pdf::MODE_UTF8, 'format' => Pdf::FORMAT_A4, 'orientation' => Pdf::ORIENT_PORTRAIT, 'methods' => ['SetFooter' => ['Linet 3.1 Accounting Software']]]);
         $mpdf = $pdf->api;
         //$mpdf->fonttrans['freeserif'] = 'freeserif2';
         //$mpdf->PDFAauto = true;
         $mpdf->WriteHtml($docfile);
         $file = new Files();
         $file->name = $name;
         $file->path = "docs/";
         $file->parent_type = get_class($model);
         $file->parent_id = $model->id;
         $file->hidden = 1;
         $file->public = 0;
         $file->save();
         //var_dump($file->getErrors());
         //exit;
         $file->writeFile($mpdf->output("bla", "S"));
     }
     $name = $model->docType->name . "-" . "{$model->docnum}-signed.pdf";
     $doc_file = PrintDoc::findFile($model, $name);
     if (!$doc_file) {
         //'digi';//
         $cerfile = User::getCertFilePath($yiiUser);
         //loads a sample PDF file
         Yii::$classMap['Farit_Pdf'] = $yiiBasepath . '/vendor/Farit/Pdf.php';
         Yii::$classMap['Farit_Pdf_ElementRaw'] = $yiiBasepath . '/vendor/Farit/ElementRaw.php';
         Yii::$classMap['Zend_Memory'] = $yiiBasepath . '/vendor/Zend/Memory.php';
         Yii::$classMap['Zend_Memory_Manager'] = $yiiBasepath . '/vendor/Zend/Memory/Manager.php';
         Yii::$classMap['Zend_Memory_Container'] = $yiiBasepath . '/vendor/Zend/Memory/Container.php';
         Yii::$classMap['Zend_Memory_Container_Interface'] = $yiiBasepath . '/vendor/Zend/Memory/Container/Interface.php';
         Yii::$classMap['Zend_Memory_Container_Locked'] = $yiiBasepath . '/vendor/Zend/Memory/Container/Locked.php';
         Yii::$classMap['Zend_Pdf'] = $yiiBasepath . '/vendor/Zend/Pdf.php';
         Yii::$classMap['Zend_Pdf_Parser'] = $yiiBasepath . '/vendor/Zend/Pdf/Parser.php';
         Yii::$classMap['Zend_Pdf_Page'] = $yiiBasepath . '/vendor/Zend/Pdf/Page.php';
         Yii::$classMap['Zend_Pdf_UpdateInfoContainer'] = $yiiBasepath . '/vendor/Zend/Pdf/UpdateInfoContainer.php';
         Yii::$classMap['Zend_Pdf_Target'] = $yiiBasepath . '/vendor/Zend/Pdf/Target.php';
         Yii::$classMap['Zend_Pdf_Destination'] = $yiiBasepath . '/vendor/Zend/Pdf/Destination.php';
         Yii::$classMap['Zend_Pdf_Destination_Zoom'] = $yiiBasepath . '/vendor/Zend/Pdf/Destination/Zoom.php';
         Yii::$classMap['Zend_Pdf_Destination_Explicit'] = $yiiBasepath . '/vendor/Zend/Pdf/Destination/Explicit.php';
         Yii::$classMap['Zend_Pdf_RecursivelyIteratableObjectsContainer'] = $yiiBasepath . '/vendor/Zend/Pdf/RecursivelyIteratableObjectsContainer.php';
         Yii::$classMap['Zend_Pdf_StringParser'] = $yiiBasepath . '/vendor/Zend/Pdf/StringParser.php';
         Yii::$classMap['Zend_Pdf_ElementFactory'] = $yiiBasepath . '/vendor/Zend/Pdf/' . 'ElementFactory' . '.php';
         Yii::$classMap['Zend_Pdf_ElementFactory_Interface'] = $yiiBasepath . '/vendor/Zend/Pdf/ElementFactory/' . 'Interface' . '.php';
         Yii::$classMap['Zend_Pdf_ElementFactory_Proxy'] = $yiiBasepath . '/vendor/Zend/Pdf/ElementFactory/Proxy.php';
         Yii::$classMap['Zend_Pdf_Element_Reference_Table'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Reference/Table.php';
         Yii::$classMap['Zend_Pdf_Element_Reference_Context'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Reference/Context.php';
         Yii::$classMap['Zend_Pdf_Element_Dictionary'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Dictionary.php';
         Yii::$classMap['Zend_Pdf_Element'] = $yiiBasepath . '/vendor/Zend/Pdf/Element.php';
         Yii::$classMap['Zend_Pdf_Element_Object'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Object.php';
         Yii::$classMap['Zend_Pdf_Element_Null'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Null.php';
         Yii::$classMap['Zend_Pdf_Element_Name'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Name.php';
         Yii::$classMap['Zend_Pdf_Element_Numeric'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Numeric.php';
         Yii::$classMap['Zend_Pdf_Element_Reference'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Reference.php';
         Yii::$classMap['Zend_Pdf_Element_Array'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Array.php';
         Yii::$classMap['Zend_Pdf_Element_String'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/String.php';
         Yii::$classMap['Zend_Pdf_Element_String_Binary'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/String/Binary.php';
         Yii::$classMap['Zend_Pdf_Trailer'] = $yiiBasepath . '/vendor/Zend/Pdf/Trailer.php';
         Yii::$classMap['Zend_Pdf_Trailer_Keeper'] = $yiiBasepath . '/vendor/Zend/Pdf/Trailer/Keeper.php';
         $pdf = \Farit_Pdf::load($file->getFullFilePath());
         if (file_exists($cerfile)) {
             $certificate = file_get_contents($cerfile);
             if (empty($certificate)) {
                 throw new \Exception('Cannot open the certificate file');
             }
             $pdf->attachDigitalCertificate($certificate, $configCertpasswd);
             $docfile = $pdf->render();
             $doc_file = new Files();
             $doc_file->name = $name;
             $doc_file->path = "docs/";
             $doc_file->parent_type = get_class($model);
             $doc_file->parent_id = $model->id;
             $doc_file->public = 1;
             $doc_file->hidden = 0;
             $doc_file->save();
             $doc_file->writeFile($docfile);
         } else {
             $link = "";
             $text = Yii::t('app', "Error! <br />\nIt is not possible to create a digitally signed PDF file and/or send it by mail without having certificate file located at current users' configuration page.\nYou should make a certificate file with third party software and import it through 'certificate file' field, separately for each user, within configuration zone of the user. You also should input the password for the certificate file in 'password for digital signature certificate' field in the above mentioned user configuration page.\nYou can find instructions for making self signed certificate file with Acrobat reader (One of the options. There are many applications able to make such a certificate out there)  here: ");
             throw new \Exception($text);
             //Yii::$app->end();
         }
     }
     return $doc_file;
 }
Exemple #13
0
 public function backupDB()
 {
     $dumper = new dbMaster();
     $sql = $dumper->getDump(false);
     $file = new Files();
     $file->name = "DB Backup " . date("d-m-Y_H_i") . ".sql";
     $file->path = '.';
     $file->save();
     $file->writeFile($sql);
     $this->DBback = $file->id;
 }
Exemple #14
0
 public function backup()
 {
     $folder = $this->getFilePath($this);
     $file = $folder . "db.json";
     $dumper = new dbMaster();
     $handle = fopen($file, 'w');
     fwrite($handle, \yii\helpers\Json::encode($dumper->newBackup($this->prefix)));
     fclose($handle);
     Zipper::zip($folder, $folder . "tenant.zip", "backup");
     $file = new Files();
     $file->name = date("d-m-Y_H_i") . ".zip";
     $file->path = 'backup' . DIRECTORY_SEPARATOR;
     $file->save();
     if (!is_dir($folder . $file->path)) {
         mkdir($folder . $file->path);
     }
     rename($folder . "tenant.zip", $folder . $file->path . $file->id);
     return true;
 }
Exemple #15
0
 public function make($cid)
 {
     $this->id = rand(0, 999999);
     //$this->iniArr=array('b110'=>0,'b100'=>0,'m100'=>0,'c100'=>0,'d100'=>0,'d110'=>0,'d120'=>0,);
     //$this->docArr=array(0=>0,305=>0,300=>0,);
     $bkmv = '';
     //$this->line=1;
     //$yiidatetimesec=Yii::$app->locale->getDateFormat('yiidatetimesec');
     //$phpdbdatetime=Yii::$app->locale->getDateFormat('phpdbdatetime');
     $from_date = $this->from_date . " 00:00:00";
     $to_date = $this->to_date . " 23:59:59";
     //$types=array(3,4,9,11,13,14);
     //accounts
     $accounts = Accounts::find()->All();
     $record = array('id' => 'B110', 'name' => OpenFormatType::getDesc('B110'), 'count' => 0);
     foreach ($accounts as $account) {
         $this->line++;
         $bkmv .= $account->openfrmt($this->line, $from_date, $to_date);
         $record['count']++;
     }
     $this->iniArr[] = $record;
     //items
     $items = Item::find()->All();
     $record = array('id' => 'M100', 'name' => OpenFormatType::getDesc('M100'), 'count' => 0);
     foreach ($items as $item) {
         $this->line++;
         $bkmv .= $item->openfrmt($this->line, $from_date, $to_date);
         $record['count']++;
     }
     $this->iniArr[] = $record;
     //
     //transactions
     $transactions = Transactions::find()->where(['BETWEEN', 'valuedate', $from_date, $to_date])->All();
     $record = array('id' => 'B100', 'name' => OpenFormatType::getDesc('B100'), 'count' => 0);
     foreach ($transactions as $transaction) {
         $this->line++;
         $bkmv .= $transaction->openfrmt($this->line, $from_date, $to_date);
         $record['count']++;
     }
     $this->iniArr[] = $record;
     //docs
     $docs = Docs::find()->where(['BETWEEN', 'due_date', $from_date, $to_date])->All();
     //OpenFormatType::getDesc('C100')
     $record = array('id' => 'C100', 'name' => OpenFormatType::getDesc('C100'), 'count' => 0);
     $d110 = array('id' => 'D110', 'name' => OpenFormatType::getDesc('D110'), 'count' => 0);
     $d120 = array('id' => 'D120', 'name' => OpenFormatType::getDesc('D120'), 'count' => 0);
     foreach ($docs as $doc) {
         if ($doc->docType->openformat != '0') {
             $this->line++;
             $bkmv .= $doc->openfrmt($this->line, $from_date, $to_date);
             foreach ($doc->docDetailes as $detial) {
                 $this->line++;
                 $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date);
                 $d110['count']++;
             }
             foreach ($doc->docCheques as $detial) {
                 $this->line++;
                 $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date);
                 $d120['count']++;
             }
             $type = $doc->OpenfrmtType();
             $this->docArr[$type] = isset($this->docArr[$type]) ? $this->docArr[$type] + 1 : 0;
             $this->docSumArr[$type] = isset($this->docSumArr[$type]) ? $this->docSumArr[$type] + $doc->total : $doc->total;
             $record['count']++;
         }
     }
     $this->iniArr[] = $record;
     $this->iniArr[] = $d110;
     $this->iniArr[] = $d120;
     $company = \app\models\Settings::findOne(['company.name']);
     //A100
     $bkmv = $company->a100(1, $this->id, $from_date, $to_date) . $bkmv;
     //Z900
     $bkmv = $bkmv . $company->z900($this->line + 1, $this->id, $this->line + 1);
     $bkmvFile = new Files();
     $bkmvFile->name = 'bkmvdata.txt';
     $bkmvFile->path = 'openformat/';
     //
     $bkmvFile->expire = 360;
     $bkmvFile->save();
     $bkmvFile->writeFile($bkmv);
     $this->bkmvId = $bkmvFile->id;
     //A000
     $ini = $company->a000(1, $this->id, $this->line + 1, $from_date, $to_date);
     foreach ($this->iniArr as $line) {
         $ini .= $line['id'] . sprintf("%015d", $line['count']) . "\r\n";
     }
     //Z
     $iniFile = new Files();
     $iniFile->name = 'ini.txt';
     $iniFile->path = 'openformat/';
     //
     $iniFile->expire = 360;
     $iniFile->save();
     $iniFile->writeFile($ini);
     $this->iniId = $iniFile->id;
     return $this->id;
 }
Exemple #16
0
 /**
  * Отвечает за загрузку изображений из формы редактирования записи
  * @return javascript string
  * @throws NotFoundHttpException if the model cannot be found
  */
 function actionUpload()
 {
     //return  ("<script>top.$('.mce-btn.mce-open').parent().find('.mce-textbox').val('/uploads/555efba5c24a7.jpg').closest('.mce-window').find('.mce-primary').click();</script>" );
     $upload_model = new UploadForm();
     $upload_model->load(yii::$app->request->post());
     $file = UploadedFile::getInstance($upload_model, 'file');
     if ($file->error === UPLOAD_ERR_OK) {
         try {
             $file_model = new Files();
             $file_model->saveImageFile($file);
             $file_model->post_id = $upload_model->post_id;
             $file_model->save();
             return "<script>top.\$('.mce-btn.mce-open').parent().find('.mce-textbox').val('/{$file_model->filename}').closest('.mce-window').find('.mce-primary').click();</script>";
         } catch (\Exception $e) {
         }
     }
     return "<script>\$.jGrowl('ошибка, файл не получен');</script>";
 }