J
J
JohnDaniels2018-05-11 11:38:35
Yii
JohnDaniels, 2018-05-11 11:38:35

How to make such a multiload in yii2?

Hello.
I have a post update form that generates inputs like this

<input name="Model[imageFiles][25]" type="file">
<input name="Model[imageFiles][36]" type="file">
<input name="Model[imageFiles][89]" type="file">

There can be as many inputs as you like, each has its own id (id of the file in the database)
Question: how can I get these id on the server in order to save the files correctly?
UploadedFile::getInstances($model, 'imageFiles')

returns
array(2) {
  [0]=>
  object(yii\web\UploadedFile)#223 (5) {
    ["name"]=>
    string(6) "bg.jpg"
    ["tempName"]=>
    string(39) "\phpC709.tmp"
    ["type"]=>
    string(10) "image/jpeg"
    ["size"]=>
    int(285557)
    ["error"]=>
    int(0)
  }
  [1]=>
  object(yii\web\UploadedFile)#224 (5) {
    ["name"]=>
    string(8) "matr.jpg"
    ["tempName"]=>
    string(39) "\phpC71A.tmp"
    ["type"]=>
    string(10) "image/jpeg"
    ["size"]=>
    int(10130)
    ["error"]=>
    int(0)
  }
}

i was expecting to get id as array keys.
Or maybe there is another way to pass the file ID when uploading it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ivankomolin, 2018-05-17
@ivankomolin

1. Remove from the input(type="file") id images.
2. Add inputs(type="hidden") with id of images in the same sequence as input(type="file")
3. Perform comparison on the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question