P
P
prozrost2017-02-17 10:40:32
Yii
prozrost, 2017-02-17 10:40:32

How to store multiple images in a database?

I want to save several pictures in the database (Maximum 5)
There is a field for this:

?= $form->field($Form, 'images[]')->fileInput(['multiple' => true, 'accept' => 'image/*','id'=>'gallery-photo-add'])->label(false) ?>

the model has an images field, which is also in the BLOB type database and accepts all images.
And also in the model there are fields Image_1, image_2, image_3 ...
I want to save them in the database, I wrote this:
$Form->images = UploadedFile::getInstances($Form,'images');
        $Form->image_1 = $Form->images[0];
        $Form->image_2 = $Form->images[1];
        $Form->image_3 = $Form->images[2];
        $Form->image_4 = $Form->images[3];
        $Form->image_5 = $Form->images[4];

But the error now pops up: Undefined offset: 1
This is evident because I have just uploaded one image, and here I turn to images[1], because it is in this place that it gives an error. The question is how to write the correct script for this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2017-02-17
@prozrost

The correct script for this is to store the paths to the images, not the images themselves.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question