Пробелма в том что при расширения docx, xlsx валидация возвращает false, и ошибка что расширение не совпарадет. С остальными все нормально. Не пойму что не так. Проверял documentFile->extension, все корректно. Подскажите
Rule:
Код: Выделить всё
[['documentFile'], 'file', 'skipOnEmpty' => false, 'extensions' => 'doc, docx, ppt, pptx, xls, xlsx, pdf, png, jpg, jpeg'],
Код: Выделить всё
public function upload ()
{
$this->filename = md5($this->original_name . time() . $this->proposal_id) . '.' . $this->documentFile->extension;
$this->original_name = $this->documentFile->baseName . '.' . $this->documentFile->extension;
if ($this->validate()) {
$path = Yii::getAlias('@webroot') . '/uploads/' . $this->proposal_id . '/';
FileHelper::createDirectory($path);
$this->documentFile->saveAs($path . $this->filename);
if ($this->save(false)) return true;
else return false;
} else {
return false;
}
}
Код: Выделить всё
public function actionSaveDocument ($id)
{
if (Yii::$app->request->isPost) {
$post = Yii::$app->request->post();
$document = new Document();
$document->proposal_id = $id;
if ($document->load($post)) {
$document->documentFile = UploadedFile::getInstance($document, 'documentFile');
if ($document->upload()) Yii::$app->session->addFlash('success', Yii::t('app', 'file_saved'));
else {
foreach ($document->errors as $key => $value) {
Yii::$app->session->addFlash('error', implode(',', $value));
}
}
}
}
return $this->redirect(['proposals/edit', 'id' => $id, 'page' => 'documents']);
}
Код: Выделить всё
<?php $form = ActiveForm::begin([
'action' => Url::to(['official-doc/save-document', 'part_id' => $part->id, 'prop_id' => $proposal->id]),
'id' => 'add_off_doc'
]); ?>
<?= $form->field(new \app\models\OfficialDoc(), 'documentFile')->fileInput(['class' => 'notshow'])->label(false) ?>
<?php ActiveForm::end(); ?>