-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathFileTypeGuesser.php
More file actions
103 lines (98 loc) · 3.02 KB
/
FileTypeGuesser.php
File metadata and controls
103 lines (98 loc) · 3.02 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace Liuggio\RackspaceCloudFilesBundle;
/**
*
*/
class FileTypeGuesser implements FileTypeGuesserInterface
{
private static $association_extension_default = 'txt';
private static $association_extension_fileType = array(
'xls'=>'application/excel',
'hqx'=>'application/macbinhex40',
'doc'=>'application/msword',
'dot'=>'application/msword',
'wrd'=>'application/msword',
'pdf'=>'application/pdf',
'pgp'=>'application/pgp',
'ps'=>'application/postscript',
'eps'=>'application/postscript',
'ai'=>'application/postscript',
'ppt'=>'application/powerpoint',
'rtf'=>'application/rtf',
'tgz'=>'application/x-gtar',
'gtar'=>'application/x-gtar',
'gz'=>'application/x-gzip',
'php'=>'application/x-httpd-php',
'php3'=>'application/x-httpd-php',
'php4'=>'application/x-httpd-php',
'js'=>'application/x-javascript',
'ppd'=>'application/x-photoshop',
'psd'=>'application/x-photoshop',
'swf'=>'application/x-shockwave-flash',
'swc'=>'application/x-shockwave-flash',
'rf'=>'application/x-shockwave-flash',
'tar'=>'application/x-tar',
'zip'=>'application/zip',
'mid'=>'audio/midi',
'midi'=>'audio/midi',
'kar'=>'audio/midi',
'mp2'=>'audio/mpeg',
'mp3'=>'audio/mpeg',
'mpga'=>'audio/mpeg',
'ra'=>'audio/x-realaudio',
'wav'=>'audio/wav',
'bmp'=>'image/bitmap',
'gif'=>'image/gif',
'iff'=>'image/iff',
'jb2'=>'image/jb2',
'jpg'=>'image/jpeg',
'jpe'=>'image/jpeg',
'jpeg'=>'image/jpeg',
'jpx'=>'image/jpx',
'png'=>'image/png',
'tif'=>'image/tiff',
'tiff'=>'image/tiff',
'wbmp'=>'image/vnd.wap.wbmp',
'xbm'=>'image/xbm',
'css'=>'text/css',
'txt'=>'text/plain',
'htm'=>'text/html',
'html'=>'text/html',
'xml'=>'text/xml',
'xsl'=>'text/xsl',
'mpg'=>'video/mpeg',
'mpe'=>'video/mpeg',
'mpeg'=>'video/mpeg',
'qt'=>'video/quicktime',
'mov'=>'video/quicktime',
'avi'=>'video/x-ms-video',
'eml'=>'message/rfc822'
);
/**
* @param string $filename
* @return string
*/
protected static function getExtensionByFilename($filename)
{
$ext = substr(strrchr($filename, '.'), 1);
if(!$ext) {
return self::$association_extension_default;
}
return $ext;
}
/**
* Attempt to get the content-type of a file based on the extension
* @static
* @param $filename
* @return string|false
*/
public static function guessByFileName($filename)
{
$extension = self::getExtensionByFilename($filename);
if (array_key_exists($extension, self::$association_extension_fileType)) {
return self::$association_extension_fileType[$extension];
} else {
return false;
}
}
}