| Current Path : /var/www/html/brspace/frontend/models/ |
| Current File : /var/www/html/brspace/frontend/models/PdfDocumentLinks.php |
<?php
namespace frontend\models;
use Yii;
use yii\web\UploadedFile;
/**
* This is the model class for table "pdf_document_links".
*
* @property int $id
* @property string $url
* @property string $file_name
* @property string $created_at
*/
class PdfDocumentLinks extends \yii\db\ActiveRecord
{
//file property
public $file;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'pdf_document_links';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['created_at', 'file'], 'safe'],
[['url'], 'string', 'max' => 500],
[['file_name'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'url' => 'Url',
'file_name' => 'File Name',
'created_at' => 'Created At',
];
}
public function upload($field, $path)
{
$this->{$field} = UploadedFile::getInstance($this, $field);
$bytes = random_bytes(5);
$rand = bin2hex($bytes);
if(!empty($this->{$field}))
$this->{$path} = 'uploads/pdf-document-link/' . $this->{$field}->baseName . '-' . $rand . '.' . $this->{$field}->extension;
return $this;
}
public function saveFile($field, $path)
{
if(!empty($this->{$field})) {
return $this->{$field}->saveAs($this->{$path});
}
}
}