FileValidate.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\common\library\storage;
  13. class FileValidate extends \think\Validate
  14. {
  15. // 验证规则
  16. protected $rule = [
  17. // 文件大小: 2MB = (1024 * 1024 * 2) = 2097152 字节
  18. // 文件扩展名: jpg,jpeg,png,bmp,gif
  19. 'image' => 'filesize:2097152|fileExt:jpg,jpeg,png,bmp,gif',
  20. 'annex' => 'filesize:2097152|fileExt:xls',
  21. ];
  22. // 错误提示信息
  23. protected $message = [
  24. 'image.filesize' => '文件大小不能超出2MB',
  25. 'image.fileExt' => '文件扩展名有误',
  26. 'annex.filesize' => '文件大小不能超出2MB',
  27. 'annex.fileExt' => '不支持的文件格式',
  28. ];
  29. // 验证场景
  30. protected $scene = [
  31. 'image' => ['image'],
  32. 'annex' => ['annex'],
  33. ];
  34. }