首页 > 杂记 > 正文

添加对 webp、ico、svg文件的支持即可

1
2
3
4
5
6
7
add_filter('upload_mimes', 'tbi_upload_mimes');
function tbi_upload_mimes($mimes = array()) {
    $mimes['svg'] = 'image/svg+xml';
    $mimes['ico'] = 'image/x-icon';
    $mimes['webp'] = 'image/webp';
    return $mimes;
}

其他文件类型 MIME 类型参考:

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
    $mimes['jpg|jpeg|jpe'] = 'image/jpeg'
    $mimes['gif'] = 'image/gif'
    $mimes['png'] = 'image/png'
    $mimes['bmp'] = 'image/bmp'
    $mimes['tiff|tif'] = 'image/tiff'
    $mimes['ico'] = 'image/x-icon'
    $mimes['asf|asx'] = 'video/x-ms-asf'
    $mimes['wmv'] = 'video/x-ms-wmv'
    $mimes['wmx'] = 'video/x-ms-wmx'
    $mimes['wm'] = 'video/x-ms-wm'
    $mimes['avi'] = 'video/avi'
    $mimes['divx'] = 'video/divx'
    $mimes['flv'] = 'video/x-flv'
    $mimes['mov|qt'] = 'video/quicktime'
    $mimes['mpeg|mpg|mpe'] = 'video/mpeg'
    $mimes['mp4|m4v'] = 'video/mp4'
    $mimes['ogv'] = 'video/ogg'
    $mimes['webm'] = 'video/webm'
    $mimes['mkv'] = 'video/x-matroska'
    $mimes['3gp|3gpp'] = 'video/3gpp'
    $mimes['3g2|3gp2'] = 'video/3gpp2'
    $mimes['txt|asc|c|cc|h|srt'] = 'text/plain'
    $mimes['csv'] = 'text/csv'
    $mimes['tsv'] = 'text/tab-separated-values'
    $mimes['ics'] = 'text/calendar'
    $mimes['rtx'] = 'text/richtext'
    $mimes['css'] = 'text/css'
    $mimes['htm|html'] = 'text/html'
    $mimes['vtt'] = 'text/vtt'
    $mimes['dfxp'] = 'application/ttaf+xml'
    $mimes['mp3|m4a|m4b'] = 'audio/mpeg'
    $mimes['aac'] = 'audio/aac'
    $mimes['ra|ram'] = 'audio/x-realaudio'
    $mimes['wav'] = 'audio/wav'
    $mimes['ogg|oga'] = 'audio/ogg'
    $mimes['flac'] = 'audio/flac'
    $mimes['mid|midi'] = 'audio/midi'
    $mimes['wma'] = 'audio/x-ms-wma'
    $mimes['wax'] = 'audio/x-ms-wax'
    $mimes['mka'] = 'audio/x-matroska'
    $mimes['rtf'] = 'application/rtf'
    $mimes['js'] = 'application/javascript'
    $mimes['pdf'] = 'application/pdf'
    $mimes['class'] = 'application/java'
    $mimes['tar'] = 'application/x-tar'
    $mimes['zip'] = 'application/zip'
    $mimes['gz|gzip'] = 'application/x-gzip'
    $mimes['rar'] = 'application/rar'
    $mimes['7z'] = 'application/x-7z-compressed'
    $mimes['psd'] = 'application/octet-stream'
    $mimes['xcf'] = 'application/octet-stream'
    $mimes['doc'] = 'application/msword'
    $mimes['pot|pps|ppt'] = 'application/vnd.ms-powerpoint'
    $mimes['wri'] = 'application/vnd.ms-write'
    $mimes['xla|xls|xlt|xlw'] = 'application/vnd.ms-excel'
    $mimes['mdb'] = 'application/vnd.ms-access'
    $mimes['mpp'] = 'application/vnd.ms-project'
    $mimes['docx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
    $mimes['docm'] = 'application/vnd.ms-word.document.macroEnabled.12'
    $mimes['dotx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'
    $mimes['dotm'] = 'application/vnd.ms-word.template.macroEnabled.12'
    $mimes['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    $mimes['xlsm'] = 'application/vnd.ms-excel.sheet.macroEnabled.12'
    $mimes['xlsb'] = 'application/vnd.ms-excel.sheet.binary.macroEnabled.12'
    $mimes['xltx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'
    $mimes['xltm'] = 'application/vnd.ms-excel.template.macroEnabled.12'
    $mimes['xlam'] = 'application/vnd.ms-excel.addin.macroEnabled.12'
    $mimes['pptx'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
    $mimes['pptm'] = 'application/vnd.ms-powerpoint.presentation.macroEnabled.12'
    $mimes['ppsx'] = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow'
    $mimes['ppsm'] = 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
    $mimes['potx'] = 'application/vnd.openxmlformats-officedocument.presentationml.template'
    $mimes['potm'] = 'application/vnd.ms-powerpoint.template.macroEnabled.12'
    $mimes['ppam'] = 'application/vnd.ms-powerpoint.addin.macroEnabled.12'
    $mimes['sldx'] = 'application/vnd.openxmlformats-officedocument.presentationml.slide'
    $mimes['sldm'] = 'application/vnd.ms-powerpoint.slide.macroEnabled.12'
    $mimes['onetoc|onetoc2|onetmp|onepkg'] = 'application/onenote'
    $mimes['oxps'] = 'application/oxps'
    $mimes['xps'] = 'application/vnd.ms-xpsdocument'
    $mimes['odt'] = 'application/vnd.oasis.opendocument.text'
    $mimes['odp'] = 'application/vnd.oasis.opendocument.presentation'
    $mimes['ods'] = 'application/vnd.oasis.opendocument.spreadsheet'
    $mimes['odg'] = 'application/vnd.oasis.opendocument.graphics'
    $mimes['odc'] = 'application/vnd.oasis.opendocument.chart'
    $mimes['odb'] = 'application/vnd.oasis.opendocument.database'
    $mimes['odf'] = 'application/vnd.oasis.opendocument.formula'
    $mimes['wp|wpd'] = 'application/wordperfect'
    $mimes['key'] = 'application/vnd.apple.keynote'
    $mimes['numbers'] = 'application/vnd.apple.numbers'
    $mimes['pages'] = 'application/vnd.apple.pages'

版权声明:部分文章、图片等内容为用户发布或互联网整理而来,仅供学习参考。如有侵犯您的版权,请联系我们,将立刻删除。