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;
} 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();
}