作者 邓超

1

... ... @@ -63,7 +63,7 @@ class Home extends Base {
* @time 2023/2/18 17:32
*/
public function send_mail(){
return print_r(app()->file('files'),true);
$email = $this->getEmail();
$formData = Verify::checks([
... ... @@ -75,7 +75,7 @@ class Home extends Base {
'files|'.__('files_email') => [
'file'=>[
'ext' => [],
'size' => 1024*1024,
'size' => 500,
'mine' => []
]
],
... ...
... ... @@ -42,7 +42,10 @@ return [
'verify_in' => '%s必须在(%s)中',
'verify_string' => '%s必须是字符串',
'verify_array_or_string' => '%s必须是%s数组或者字符串',
'verify_file' => '%s必须文件',
'verify_file' => '%s必须是文件',
'verify_file.ext' => '%s上传的文件(%s)后缀必须是%s',
'verify_file.mine' => '%s上传的文件(%s)类型必须是%s',
'verify_file.size' => '%s上传的文件(%s)大小必须在%skb以内',
... ...
... ... @@ -238,7 +238,7 @@ class App {
/**
* 错误
* @param string $message
* @param string|array $message
* @param int $status
* @throws Err
* @author:dc
... ...
... ... @@ -169,12 +169,12 @@ class Verify {
/**
* 必须
* @param $key
* @return false
* @return bool
* @author:dc
* @time 2023/3/13 10:11
* @time 2023/3/13 17:14
*/
public function required($key){
return $this->_get($key) !== '';
return $this->_get($key) !== '' || app()->file($key);
}
... ... @@ -388,7 +388,37 @@ class Verify {
* @time 2023/3/13 14:27
*/
public function file($key,$value){
$files = app()->file($key);
if($files){
foreach ($files as $file){
// 后缀
if(!empty($value['ext'])){
$value['ext'] = is_string($value['ext']) ? [$value['ext']] : [];
if (!in_array($file->ext,$value['ext'])){
app()->e(['verify_file.ext',[$this->alias[$key],$file->name,implode('|',$value['ext'])]],600);
return false;
}
}
// 类型
if(!empty($value['mine'])){
$value['mine'] = is_string($value['mine']) ? [$value['mine']] : [];
if (!in_array($file->mime,$value['mine'])){
app()->e(['verify_file.mine',[$this->alias[$key],$file->name,implode('|',$value['mine'])]],600);
return false;
}
}
// 大小
if(!empty($value['size'])){
if ($file->size > $value['size']){
app()->e(['verify_file.size',[$this->alias[$key],$file->name,$value['size']]],600);
return false;
}
}
}
}
return true;
}
... ...