コード例 #1
0
 /**
  *
  */
 public function run()
 {
     $message = null;
     if (empty($_FILES['upload']['name'])) {
         $message = Yii::t('YupeModule.yupe', 'There is an error when downloading!');
     }
     // по умолчанию не переименовываем файл
     $this->rename = (bool) Yii::app()->getRequest()->getQuery('rename', false);
     $this->webPath = '/' . $this->getController()->yupe->uploadPath . '/files/' . date('Y/m/d') . '/';
     $this->uploadPath = Yii::getPathOfAlias('webroot') . $this->webPath;
     if (!is_dir($this->uploadPath)) {
         if (!@mkdir($this->uploadPath, 0755, true)) {
             $message = Yii::t('YupeModule.yupe', 'Can\'t create catalog "{dir}" for files!', array('{dir}' => $this->uploadPath));
         }
     }
     $this->getController()->disableProfilers();
     $this->uploadedFile = CUploadedFile::getInstanceByName('upload');
     $form = new UploadForm();
     $form->maxSize = $this->maxSize ?: null;
     $form->mimeTypes = $this->mimeTypes ?: null;
     $form->types = $this->types ?: null;
     $form->file = $this->uploadedFile;
     if ($form->validate() && $this->uploadFile() && ($this->fileLink !== null && $this->fileName !== null)) {
         $fullPath = $this->fileLink;
         //'filename' => $this->fileName;
     } else {
         $message = implode("\n", $form->getErrors("file"));
     }
     $callback = Yii::app()->getRequest()->getParam('CKEditorFuncNum');
     echo '<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction("' . $callback . '", "' . $fullPath . '", "' . $message . '" );</script>';
     Yii::app()->end();
 }
コード例 #2
0
 /**
  * @throws \CHttpException
  */
 public function run()
 {
     if (!Yii::app()->getRequest()->getIsPostRequest()) {
         throw new \CHttpException(404);
     }
     if (empty($_FILES['file']['name'])) {
         Yii::app()->ajax->raw(['error' => Yii::t('YupeModule.yupe', 'There is an error when downloading!')]);
     }
     $this->webPath = '/' . $this->getController()->yupe->uploadPath . '/files/' . date('Y/m/d') . '/';
     $this->uploadPath = Yii::getPathOfAlias('webroot') . $this->webPath;
     if (!is_dir($this->uploadPath)) {
         if (!@mkdir($this->uploadPath, 0755, true)) {
             Yii::app()->ajax->raw(['error' => Yii::t('YupeModule.yupe', 'Can\'t create catalog "{dir}" for files!', ['{dir}' => $this->uploadPath])]);
         }
     }
     $this->getController()->disableProfilers();
     $this->uploadedFile = CUploadedFile::getInstanceByName('file');
     $form = new UploadForm();
     $form->maxSize = $this->maxSize ?: null;
     $form->mimeTypes = $this->mimeTypes ?: null;
     $form->types = $this->types ?: null;
     $form->file = $this->uploadedFile;
     if ($form->validate() && $this->uploadFile() && ($this->fileLink !== null && $this->fileName !== null)) {
         Yii::app()->ajax->raw(['filelink' => $this->fileLink, 'filename' => $this->fileName]);
     } else {
         Yii::app()->ajax->raw(['error' => join("\n", $form->getErrors("file"))]);
     }
 }
コード例 #3
0
 /**
  * Метод для загрузки файлов из редактора при создании контента
  *
  * @since 0.4
  *
  * Подробнее http://imperavi.com/redactor/docs/images/
  *
  * @return void
  */
 public function run()
 {
     if (empty($this->maxSize) || empty($this->mimeTypes) || empty($this->types)) {
         Yii::app()->ajax->rawText(Yii::t('YupeModule.yupe', 'Please, proper config YAjaxFileUploadAction !'));
     }
     if (empty($_FILES['file']['name'])) {
         Yii::app()->ajax->rawText(Yii::t('YupeModule.yupe', 'There is an error when downloading!'));
     }
     $this->rename = (bool) Yii::app()->getRequest()->getQuery('rename', true);
     $this->webPath = '/' . $this->getController()->yupe->uploadPath . '/' . date('dmY') . '/';
     $this->uploadPath = Yii::getPathOfAlias('webroot') . $this->webPath;
     if (!is_dir($this->uploadPath)) {
         if (!@mkdir($this->uploadPath)) {
             Yii::app()->ajax->rawText(Yii::t('YupeModule.yupe', 'Can\'t create catalog "{dir}" for files!', array('{dir}' => $this->uploadPath)));
         }
     }
     $this->getController()->disableProfilers();
     $this->uploadedFile = CUploadedFile::getInstanceByName('file');
     $form = new UploadForm();
     $form->maxSize = $this->maxSize;
     $form->mimeTypes = $this->mimeTypes;
     $form->types = $this->types;
     $form->file = $this->uploadedFile;
     if ($form->validate() && $this->uploadFile() && ($this->fileLink !== null && $this->fileName !== null)) {
         Yii::app()->ajax->rawText(json_encode(array('filelink' => $this->fileLink, 'filename' => $this->fileName)));
     }
     Yii::app()->ajax->rawText(Yii::t('YupeModule.yupe', 'There is an error when downloading!'));
 }