M
M
Mikha Pankratov2015-04-08 13:24:45
Yii
Mikha Pankratov, 2015-04-08 13:24:45

Yii2 how to make image update?

Good afternoon,
I want to update the record of pictures, I use
use kartik\file\FileInput;
Here is the action code itself

$dir = Yii::getAlias('@app/web/uploads/');
        $uploaded = false;
        $model = new Programs();

        if($_POST){
            if (Yii::$app->request->isAjax) {
                Yii::$app->response->format = Response::FORMAT_JSON;
                return ActiveForm::validate($model);
            }else{
                $model->load(Yii::$app->request->post('Programs'));
                $programs = Yii::$app->request->post('Programs');

                $guid = UploadedFile::getInstance($model, 'guid');
                $extension = strtolower(substr(strrchr($guid->name, '.'), 1));
                $filename = DFileHelper::getRandomFileName($dir, $extension);
                $model->title = $programs['title'];
                $model->description = $programs['description'];
                $model->text = isset($programs['text']) ? $programs['text'] : '';
                $model->time_show = isset($programs['time_show']) ? $programs['time_show'] : '';

                if ($model->validate()) {
                    $uploaded = $guid->saveAs( $dir . $filename.'.'. $extension );
                    $model->guid = EasyThumbnailImage::thumbnailFile($dir . $filename.'.'. $extension, 341, 227);
                    $model->flag = 1;

                    if ($model->save()){
                        Yii::$app->response->redirect(array('blog/read', 'id' => $model->id));
                    }
                }
            }
        }

fall for some reason here
$guid = UploadedFile::getInstance($model, 'guid');
var_dump($model->guid) //produces null
Tell me what to check where to look?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2015-04-08
@frmax

show the form generation code. sure you didn't set
<?php $form = ActiveForm::begin([
'options' => ['enctype'=>'multipart/form-data']
]); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question