Answer the question
In order to leave comments, you need to log in
How to store multiple yii files in db?
It is not possible to upload multiple files, or rather save them to the database.
What should be stored in the database when there are several files?
There is a table, it has a blob type attribute that is designed to store photos. In the off-doc it is written to create a model for loading and validating files, but what should I write in the attribute of the file storage table?
$uploadFileModel = new UploadFile(); // модель как в офф доке
$model = new Model();
if ($model->load(Yii::$app->request->post())) {
$uploadFileModel->imageFile = UploadedFile::getInstances($uploadFileModel, 'imageFile');
if ($uploadFileModel->upload()) {
$model->Scan = // не знаю что писать сюда
Answer the question
In order to leave comments, you need to log in
It is better to store paths to images in the database, and the images themselves in the file system - for example, in the Uploads folder.
If you can have many images, then create a one-to-many or many-to-many relationship in the database and store the image paths in a separate table.
For example, if you have a Post table and each post has MB of images, then add a PostImage table with fields post_id | image_path.
Thus, you can always easily get the path to all the images of any post.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question