M
M
Mikha Pankratov2016-07-16 17:57:28
Yii
Mikha Pankratov, 2016-07-16 17:57:28

How to update image from kartik/fileinput?

Good afternoon, I'm parsing the
kart/fileinput
https://github.com/kartik-v/yii2-widget-fileinput
So I got to the part where I need to update the pictures, I did the deletion and update the picture.
I send the image to the server. Here's what came
in var_dump($_POST, $_FILES);

array(1) {
  ["file_id"]=>
  string(1) "2"
}
array(1) {
  ["photo_image"]=>
  array(5) {
    ["name"]=>
    array(1) {
      [0]=>
      string(12) "02151004.JPG"
    }
    ["type"]=>
    array(1) {
      [0]=>
      string(10) "image/jpeg"
    }
    ["tmp_name"]=>
    array(1) {
      [0]=>
      string(14) "/tmp/phpjHYX2D"
    }
    ["error"]=>
    array(1) {
      [0]=>
      int(0)
    }
    ["size"]=>
    array(1) {
      [0]=>
      int(6258693)
    }
  }
}

This is the first thing that bothered me.
Okay, I initialize the picture,
if(\Yii::$app->request->isPost) {
            $photos = new Photo();
            $photos->photo_image = UploadedFile::getInstance($photos, 'photo_image');
            var_dump($photos); //photo_image = null

I don't get it, what's the deal? And why the picture does not initialize + the post is almost empty.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2016-07-16
@kimono

Try UploadedFile::getInstances.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question