fluxcms /inc/popoon/helpers/mimetypes.php

Language PHP Lines 82
MD5 Hash a231c4d9a9e5737b90e46c1167cb117a
Repository https://github.com/chregu/fluxcms.git View Raw File View Project SPDX
 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
<?php


class popoon_helpers_mimetypes {


    static function getFromFileLocation($src) {
        $extension = strtolower(substr($src,strrpos($src,".")+1));
	if ($src == ".") {
		return "httpd/unix-directory";
	}
        switch ($extension) {
            case "gif":
            return "image/gif";
            case "jpg":
            case "jpeg":
            return "image/jpeg";
            case "png":
            return "image/png";
            case "css":
            return "text/css";
            case "xml":
            case "xsl":
            case "xsd":
            case "rng":
            case "tal":
            case "configxml":
            case "children":
            return "text/xml";
            case "js":
            return "text/javascript";
            case "html":
            case "htm":
            case "xhtml":
             return "text/html";
            case "txt":
            return "text/plain";
            case "pdf":
            return "application/pdf";
            case "zip":
            return "application/zip";
            case "gz":
            case "tgz":
            return "application/x-gzip";
            case "bz2":
            return "application/x-bz2";
            case "tar":
            return "application/x-gtar";
            case "torrent":
            return "application/x-bittorrent";
            case "mp3":
            return "audio/mpeg";
            case "doc":
            return "application/msword";
            case "xls":
            return "application/vnd.ms-excel";
            case "ppt":
            return "application/vnd.ms-powerpoint";
            
            default:
            
            if (strpos($src,"://") == false && file_exists($src)) {
                if (function_exists("finfo_open")) {
                    $res = finfo_open(FILEINFO_MIME);
                    $m = finfo_file($res, $src);
                    finfo_close($res);
                } elseif(!strpos(ini_get('disable_functions'),'exec')) {
                    exec(escapeshellcmd('file -ib '. escapeshellarg($src)), $out);
                    $m = array_shift($out);
                }
                if (isset($m)) {
                    return $m;
                }
            }
            return "application/octet-stream";
        }


    }

}
Back to Top