MongoDB
 sql >> Teknologi Basis Data >  >> NoSQL >> MongoDB

Simpan Banyak File Gambar Menggunakan Widget Kartik FileInput

Coba ini:

Controller:Anda harus menyimpan nama gambar di database('$model->urls')

public function actionUpload()
{
        $model = new Upload();

        if ($model->load(Yii::$app->request->post())) {
            $model->file = UploadedFile::getInstances($model, 'file');
            foreach ($model->file as $key => $file) {

                $file->saveAs('/uploads/'. $file->baseName . '.' . $file->extension);//Upload files to server
                $model->urls .= 'uploads/' . $file->baseName . '.' . $file->extension.'**';//Save file names in database- '**' is for separating images
            }
            $model->save();
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('upload', [
                'model' => $model,
            ]);
        }
}

Lihat

<?= $form->field($model, 'file[]')->widget(FileInput::classname(), [
'options' => ['multiple' => 'true'],
]) ?>

Model

class Upload extends Model
{
public $file;
public function rules()
{
    return [
        [['file'], 'file','maxFiles' => 6],
        [['urls'],'string'],

    ];
}

Tampilan lain untuk menampilkan gambar

<?php
$images=explode('**',trim($model->urls));
foreach($images as $image)
{
     echo Html::img(Url::to('@web/' . $image, true));
}
?>


  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. Buat kombinasi dua bidang unik dalam koleksi saya

  2. Kelompokkan berdasarkan nilai dan kondisi

  3. Populate() ref bersarang di array objek

  4. Tren NoSQL – MongoDB, Cassandra, CouchDB &Riak

  5. cara mengonfigurasi bidang debezium yang dikirim pada acara pembaruan (konektor mongo)