M
M
Max DangerPro2016-11-27 22:48:54
Yii
Max DangerPro, 2016-11-27 22:48:54

How to add the name of the uploaded file to the database in Yii2?

I'm uploading a file. In the controller I wrote:

$model->file = UploadedFile::getInstance($model, 'file');
            if($model->uploadFile()) {
                return;
            }

In the model:
public function uploadFile() {
        if ($model->validate()) {
            $path = Yii::getAlias('@webroot/upload/global/books/');
            $model->file->saveAs($path.$model->file->baseName.'.'.$model->file->extension);
            return;
        } else { return false; }
    }

The file is loaded successfully, only for some reason the Russian letters change to crocodile. Who will tell?
How to add the name of the uploaded file to the database in the "file" field?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2016-11-29
@koshalex

answer pzh how did you remove the krakozyabry

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question