|
12 | 12 | use Psr\Http\Message\{MessageInterface, RequestInterface, ResponseInterface, UriInterface};
|
13 | 13 |
|
14 | 14 | use function array_filter, array_map, explode, extension_loaded, function_exists, gzdecode, gzinflate, gzuncompress, implode,
|
15 |
| - is_array, is_scalar, json_decode, json_encode, parse_url, preg_match, preg_replace_callback, rawurldecode, |
| 15 | + is_array, is_scalar, json_decode, json_encode, parse_url, pathinfo, preg_match, preg_replace_callback, rawurldecode, |
16 | 16 | rawurlencode, simplexml_load_string, strtolower, trim, urlencode;
|
17 | 17 |
|
| 18 | +use const PATHINFO_EXTENSION; |
| 19 | + |
18 | 20 | const CHILLERLAN_PSR7_UTIL_INCLUDES = true;
|
19 | 21 |
|
20 | 22 | /**
|
|
123 | 125 | 'zip' => 'application/zip',
|
124 | 126 | ];
|
125 | 127 |
|
| 128 | +/** |
| 129 | + * Get the mime type for the given file extension |
| 130 | + */ |
| 131 | +function getMimetypeFromExtension(string $extension):?string{ |
| 132 | + return MIMETYPES[strtolower($extension)] ?? null; |
| 133 | +} |
| 134 | + |
| 135 | +/** |
| 136 | + * Get the mime type from a file name |
| 137 | + */ |
| 138 | +function getMimetypeFromFilename(string $filename):?string{ |
| 139 | + return getMimetypeFromExtension(pathinfo($filename, PATHINFO_EXTENSION)); |
| 140 | +} |
| 141 | + |
126 | 142 | /**
|
127 | 143 | * @param string|string[] $data
|
128 | 144 | *
|
|
0 commit comments