i am really new in yii2,
i want question, is it possible to have 2 fileinput in 1 models?
i have 2 browse files in views,
this is my code,
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\web\UploadedFile;
/**
-
This is the model class for table "rtc".
-
@property integer $id
-
@property string $current_rtc_correction
-
@property integer $new_rtc_correction
-
@property string $calculate_rtc_correction
-
@property string $begin_date
-
@property string $end_date
*/
class FirmwareupdatesForm extends Model
{
public $fileUpload;
public $tagPackage;
public $fileName;
public $fileLocation = '/var/tmp/';
public $folderName = array();
public $finalLocation;
public $error=" " ;
public function rules()
{
return [
[['fileUpload'], 'safe'],
[['tagPackage'], 'safe'],
];
}
public function upload()
{
if( is_null( $this->fileUpload ) )
{
//error if no file chosen
$this->error = "Error";
return;
}
if($this->validate())
{
//upload file handle
$fullpath = $this->fileLocation. $this->fileName . '.' . 'installer';
$this->fileUpload->saveAs($fullpath);
//directory to find .installer.finish
$pathToFinishFile = $fullpath.'.finish';
//execute MD5
exec("cd $this->fileLocation;md5sum $this->fileName.'installer' > $this->fileName.'installer'.finish");
//read checkbox value and selected store
foreach($this->folderName as $value)
{
$checkFolderExist = '/home/tunnel/'.$value;
if ( is_dir($checkFolderExist) == 1 )
{
//copy file .installer & .installer.finish
exec("cp $fullpath /home/tunnel/$value");
exec("cp $pathToFinishFile /home/tunnel/$value");
exec("sudo chown tunnel /home/tunnel/$value");
exec("sudo chgrp tunnel /home/tunnel/$value");
}
else
{
//make new folder
exec("sudo mkdir /home/tunnel/$value -m 777");
//change owner of folder
exec("sudo chown tunnel /home/tunnel/$value");
exec("sudo chgrp tunnel /home/tunnel/$value");
//copy file .installer & .installer.finish
exec("cp $fullpath /home/tunnel/$value");
exec("cp $pathToFinishFile /home/tunnel/$value");
}
}
//remove temporary file
exec("rm $fullpath -f");
exec("rm $pathToFinishFile -f");
return true;
}
else
{
return false;
}
}
}
?>
i want add one more action download,
is it possible?