qingjian/app/validate/Upload.php

74 lines
1.9 KiB
PHP
Raw Normal View History

2021-08-06 10:50:55 +00:00
<?php
namespace app\validate;
use think\Validate;
use app\model\System;
use think\Lang;
class Upload extends Validate
{
protected $rule = [];
protected $message = [];
protected $system;
public function __construct()
{
$this->system = System::getSystem();
$this->lang = new Lang;
}
//验证图片上传
public function checkImage($image)
{
$ext = str_replace('', ',', $this->system['img_type']);
$size = $this->system['img_size'] * 1024 * 1024;
$this->rule = [
'image' => [
'fileExt' => $ext,
'fileSize' => (int)$size
]
];
return $this->check(['image' => $image]);
}
//pdf上传
public function checkPdf($pdf)
{
$size = 3 * 1024 * 1024;//3M
$this->rule = [
'pdf' => [
'fileExt' => "pdf",
'fileSize' => (int)$size
]
];
return $this->check(['pdf' => $pdf]);
}
//验证视频上传
public function checkVideo($video)
{
$ext = str_replace('', ',', $this->system['video_type']);
$size = $this->system['video_size'] * 1024 * 1024;
$this->rule = [
'video' => [
'fileExt' => $ext,
'fileSize' => (int)$size
]
];
return $this->check(['video' => $video]);
}
//验证文件上传
public function checkFile($file)
{
$ext = str_replace('', ',', $this->system['file_type']);
$size = $this->system['file_size'] * 1024 * 1024;
$this->rule = [
'file' => [
'fileExt' => $ext,
'fileSize' => (int)$size
]
];
return $this->check(['file' => $file]);
}
}