Problem when uploading a file in yii2

0

Hello, I am trying to upload a file with spaces in the name of the file and it does not upload it, however without space in the name of the file if it uploads perfectly. I'm using Yii2.

This is my view

 <?php
$options = ($model->modo == "offline") ? ['options' => ['enctype' => 'multipart/form-data']] : [];
$form = ActiveForm::begin($options); ?>

<div class="row">
        <div class="col-lg-4">
            <?= $form->field($model, 'nombre')->textInput(['maxlength' => true]) ?>
        </div>
    </div>

echo $form->field($modelAdjunto, 'filename')->widget(FileInput::classname(), [
            'options' => ['accept' => 'pdf, doc, docx, odt'],
            'pluginOptions' => [
                'initialPreviewAsData' => false,
            ]
        ]);

<div class="form-group">
    <?= Html::submitButton('Salvar', ['class' => 'btn btn-success']) ?>
</div>

<?php ActiveForm::end(); ?>

My controller

$file = UploadedFile::getInstance($modelAdjunto, 'filename');

            $model->nombre = $file->name;
            $model->modo = "offline";
            $model->save();

            $modelAdjunto->filename = $file->name;
            $modelAdjunto->filesize = $file->size;
            $file->saveAs('uploads/' . $file->baseName . '.' . $file->extension);

            $modelAdjunto->acta_id = $model->idacta;
            $modelAdjunto->save();

Please help?

    
asked by Yoedusvany Hdez 02.06.2018 в 20:47
source

0 answers