/
file.php
55 lines (52 loc) · 1.83 KB
/
file.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Helper;
class File extends \Image
{
public static $mimeMap = array(
"image" => array(
"image/jpeg",
"image/png",
"image/gif",
"image/bmp",
),
"icon" => array(
"audio/.+" => "_audio",
"application/.*zip" => "_archive",
"application/x-php" => "_code",
"(application|text)/xml" => "_code",
"text/html" => "_code",
"image/.+" => "_image",
"application/x-photoshop" => "_image",
"video/.+" => "_video",
"application/.*pdf" => "pdf",
"text/[ct]sv" => "csv",
"text/.+-separated-values" => "csv",
"text/.+" => "txt",
"application/sql" => "txt",
"application/vnd\.oasis\.opendocument\.graphics" => "odg",
"application/vnd\.oasis\.opendocument\.spreadsheet" => "ods",
"application/vnd\.oasis\.opendocument\.presentation" => "odp",
"application/vnd\.oasis\.opendocument\.text" => "odt",
"application/(msword|vnd\.(ms-word|openxmlformats-officedocument\.wordprocessingml.+))" => "doc",
"application/(msexcel|vnd\.(ms-excel|openxmlformats-officedocument\.spreadsheetml.+))" => "xls",
"application/(mspowerpoint|vnd\.(ms-powerpoint|openxmlformats-officedocument\.presentationml.+))" => "ppt",
)
);
/**
* Get an icon name by MIME type
*
* Returns "_blank" when no icon matches
*
* @param string $contentType
* @return string
*/
public static function mimeIcon($contentType)
{
foreach (self::$mimeMap["icon"] as $regex => $name) {
if (preg_match("@^" . $regex . "$@i", $contentType)) {
return $name;
}
}
return "_blank";
}
}