forked from leftypol/leftypol
mime.php: add mime functions
This commit is contained in:
parent
78c6fe1826
commit
97ca3cca4f
1 changed files with 36 additions and 0 deletions
36
inc/functions/mime.php
Normal file
36
inc/functions/mime.php
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
namespace Vichan\Functions\Mime;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $mime Lowercase valid mime type.
|
||||||
|
* @return ?string Vichan's preferred extension for the given mime type, if any.
|
||||||
|
*/
|
||||||
|
function mime_to_ext(string $mime): ?string {
|
||||||
|
static $mime_to_ext = [
|
||||||
|
'image/jpeg' => 'jpg',
|
||||||
|
'image/png' => 'png',
|
||||||
|
'image/gif' => 'gif',
|
||||||
|
'image/webp' => 'webp',
|
||||||
|
'image/bmp' => 'bmp',
|
||||||
|
'image/avif' => 'avif'
|
||||||
|
];
|
||||||
|
return $mime_to_ext[$mime] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $mime Lowercase extension.
|
||||||
|
* @return ?string Vichan's preferred mime type for the given extensions, if any.
|
||||||
|
*/
|
||||||
|
function ext_to_mime(string $ext): ?string {
|
||||||
|
static $ext_to_mime = [
|
||||||
|
'jpg' => 'image/jpeg',
|
||||||
|
'jpeg' => 'image/jpeg',
|
||||||
|
'png' => 'image/png',
|
||||||
|
'gif' => 'image/gif',
|
||||||
|
'webp' => 'image/webp',
|
||||||
|
'bmp' => 'image/bmp',
|
||||||
|
'avif' => 'image/avif',
|
||||||
|
];
|
||||||
|
return $ext_to_mime[$ext] ?? null;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue