Добрый день. В виджете vova07/yii2-imperavi-widget пытаюсь реализовать вывод картинки.
В форме прописал:
<?php echo $form->field($model, 'text')->widget(Widget::className(), [
'settings' => [
'lang' => 'ru',
'minHeight' => 200,
'plugins' => [
'clips',
'fullscreen',
],
'imageUpload' => \yii\helpers\Url::to(['/site/save-redactor-img', 'sub'=>'blog']),
],
]);
?>
imageUpload ведёт на action SaveRedactorImg:
public function actionSaveRedactorImg($sub = 'main')
{
$this->enableCsrfValidation = false;
if (Yii::$app->request->isPost) {
$dir = Yii::getAlias('@images') . '/' . $sub . '/';
if(!file_exists($dir)) {
FileHelper::createDirectory($dir);
}
$result_link = str_replace('admin.', '', Url::home(true)) . 'uploads/images/' . $sub . '/';
$file = UploadedFile::getInstancesByName('file');
$model = new DynamicModel(compact('file'));
$model->addRule('file', 'image')->validate();
if ($model->hasErrors()) {
$result = [
'error' => $model->getFirstError('file')
];
} else {
$model->file->name = strtotime('now') . '_' . Yii::$app->getSecurity()->generateRandomString(6) . '.' . $model->file->extension;
if ($model->file->saveAs($dir . $model->file->name)) {
$result = ['filelink' => $result_link . $model->file->name, 'filename' => $model->file->name];
} else {
$result = [
'error' => Yii::t('vova07/imperavi', 'ERROR_CAN_NOT_UPLOAD_FILE')
];
}
}
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return $result;
} else {
throw new BadRequestHttpException('Only POST is allowed');
}
}
Алиас @images:
Yii::setAlias('@images', dirname(dirname(dirname(__DIR__))) . '/public_html/uploads/images');
Суть проблемы в том, что ajax запрос проходит, папка blog в upload/images создается, но фотография туда не загружается ( выдает ошибку An error occurred during the upload process!) В чём может быть проблема ? Может кто сталкивался.
Использую Advanced приложение