hyperf-chat/app/Constants/MediaTypeConstant.php

42 lines
953 B
PHP
Raw Normal View History

2021-07-01 23:10:18 +08:00
<?php
2021-09-11 12:41:28 +08:00
declare(strict_types=1);
2021-07-01 23:10:18 +08:00
namespace App\Constants;
/**
2021-07-20 23:12:18 +08:00
* Class MediaTypeConstant
2021-07-01 23:10:18 +08:00
*
* @package App\Constants
*/
2021-07-20 23:12:18 +08:00
class MediaTypeConstant
2021-07-01 23:10:18 +08:00
{
const FILE_IMAGE = 1; //图片文件
const FILE_VIDEO = 2; //视频文件
const FILE_AUDIO = 3; //音频文件
const FILE_OTHER = 4; //其它文件
const FILE_TYPES = [
'gif' => self::FILE_IMAGE,
'jpg' => self::FILE_IMAGE,
'jpeg' => self::FILE_IMAGE,
'png' => self::FILE_IMAGE,
'webp' => self::FILE_IMAGE,
'ogg' => self::FILE_VIDEO,
'mp3' => self::FILE_VIDEO,
'wav' => self::FILE_VIDEO,
'mp4' => self::FILE_AUDIO,
'webm' => self::FILE_AUDIO,
];
/**
* 获取媒体文件的类型
*
* @param string $ext 文件后缀
* @return int
*/
public static function getMediaType(string $ext): int
{
return self::FILE_TYPES[$ext] ?? self::FILE_OTHER;
}
}