hyperf-chat/app/Constants/FileMediaType.php

41 lines
920 B
PHP

<?php
namespace App\Constants;
/**
* Class FileMediaType
*
* @package App\Constants
*/
class FileMediaType
{
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;
}
}