P
P
prozrost2017-02-17 11:30:49
Yii
prozrost, 2017-02-17 11:30:49

How to store image path in db?

I save the data that came from the form in the images[] array
, I also have image_1,image_2,image_3...image_5 these are the fields in the database where I want to save the paths to the pictures
Pictures are saved like this:

$Form->images = UploadedFile::getInstances($Form,'images');
        foreach($Form->images as $file){
            $file->saveAs('uploads/' . $file->baseName . '.' . $file->extension);
        }

How now inside this loop will refer to image_1, image_2 and so on?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2017-02-17
@rpsv

$images = UploadedFile::getInstances($Form,'images');
$path1 = 'uploads/' . $images[0]->baseName . '.' . $images[0]->extension;
$image[0]->saveAs($path1);

$imageModel = new ImageModel(...);
$imageModel->image1 = $path1; 
$imageModel->image2 = $path2;
$imageModel->save();

Do you mean it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question