]> git.mxchange.org Git - friendica.git/blob - include/attach.php
Merge https://github.com/friendica/friendica into pull
[friendica.git] / include / attach.php
1 <?php
2
3
4 function z_mime_content_type($filename) {
5
6         $mime_types = array(
7
8                 'txt' => 'text/plain',
9                 'htm' => 'text/html',
10                 'html' => 'text/html',
11                 'php' => 'text/html',
12                 'css' => 'text/css',
13                 'js' => 'application/javascript',
14                 'json' => 'application/json',
15                 'xml' => 'application/xml',
16                 'swf' => 'application/x-shockwave-flash',
17                 'flv' => 'video/x-flv',
18
19                 // images
20                 'png' => 'image/png',
21                 'jpe' => 'image/jpeg',
22                 'jpeg' => 'image/jpeg',
23                 'jpg' => 'image/jpeg',
24                 'gif' => 'image/gif',
25                 'bmp' => 'image/bmp',
26                 'ico' => 'image/vnd.microsoft.icon',
27                 'tiff' => 'image/tiff',
28                 'tif' => 'image/tiff',
29                 'svg' => 'image/svg+xml',
30                 'svgz' => 'image/svg+xml',
31
32                 // archives
33                 'zip' => 'application/zip',
34                 'rar' => 'application/x-rar-compressed',
35                 'exe' => 'application/x-msdownload',
36                 'msi' => 'application/x-msdownload',
37                 'cab' => 'application/vnd.ms-cab-compressed',
38
39                 // audio/video
40                 'mp3' => 'audio/mpeg',
41                 'wav' => 'audio/wav',
42                 'qt' => 'video/quicktime',
43                 'mov' => 'video/quicktime',
44                 'ogg' => 'application/ogg',
45                 'mp4' => 'video/mp4',
46                 'avi' => 'video/x-msvideo',
47                 'wmv' => 'video/x-ms-wmv',
48                 'wma' => 'audio/x-ms-wma',
49
50                 // adobe
51                 'pdf' => 'application/pdf',
52                 'psd' => 'image/vnd.adobe.photoshop',
53                 'ai' => 'application/postscript',
54                 'eps' => 'application/postscript',
55                 'ps' => 'application/postscript',
56
57                 // ms office
58                 'doc' => 'application/msword',
59                 'rtf' => 'application/rtf',
60                 'xls' => 'application/vnd.ms-excel',
61                 'ppt' => 'application/vnd.ms-powerpoint',
62
63
64                 // open office
65                 'odt' => 'application/vnd.oasis.opendocument.text',
66                 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
67         );
68
69         $dot = strpos($filename,'.');
70         if($dot !== false) {
71                 $ext = strtolower(substr($filename,$dot+1));
72                 if (array_key_exists($ext, $mime_types)) {
73                         return $mime_types[$ext];
74                 }
75         }
76 // can't use this because we're just passing a name, e.g. not a file that can be opened
77 //      elseif (function_exists('finfo_open')) {
78 //              $finfo = @finfo_open(FILEINFO_MIME);
79 //              $mimetype = @finfo_file($finfo, $filename);
80 //              @finfo_close($finfo);
81 //              return $mimetype;
82 //      }
83         else {
84                 return 'application/octet-stream';
85         }
86 }
87