1

I want upload video in my Yii form

I try this:

$dbimage = '';
if (null != $patientmodel->treatment_videos) {
    $filename = uniqid() . '.' . $patientmodel->treatment_videos->extension;
    $patient_videos->saveAs($patientmodel->patientImgPath . '/' . $filename);
    $dbimage .= $filename . ',';
    $dbimage = rtrim($dbimage, ',');
    $patientmodel->treatment_videos = $dbimage;
}

output:I cannot select my video files

Vitaly
  • 1,261
  • 2
  • 10
  • 20
Dhaval Soni
  • 85
  • 2
  • 9

1 Answers1

2

from UploadedFile class the easy sample code is:

view.php

<?= Html::beginForm('', 'post', ['enctype' => 'multipart/form-data']) ?>
<?= Html::fileInput('attachment', '', ['id' => 'attachment']) ?>
<?= Html::submitButton('Submit') ?>
<?= Html::endForm() ?>

controller.php

if ($file = UploadedFile::getInstanceByName('attachment')) { // check if file uploaded
   if (in_array($file->extension, ['mp3', 'wav'])) { // check valid audio file extensions
      $file_size_limit = 1024 * 1024 * 10 // 10mb
      if ($file->size < $file_size_limit) { // check max file size
         $path = 'path/to/directory';
         if ($file->saveAs($path)) { 
             return 'file uploaded successfully';
         }else{
             return $file->error;
         }
      }  
   }        
}

maybe you see this problems in your file uploadings:

or for using in models you can use input Uploading Files document

ttrasn
  • 4,322
  • 4
  • 26
  • 43