Filesystem::getMimeType()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
c 0
b 0
f 0
nc 3
nop 2
dl 0
loc 23
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Filesystem Component
7
 * Founded by Sergey Romanenko and maintained by Community.
8
 */
9
10
namespace Flextype\Component\Filesystem;
11
12
use FilesystemIterator;
13
use RecursiveDirectoryIterator;
14
use RecursiveIteratorIterator;
15
use SplFileInfo;
16
use const FILEINFO_MIME_TYPE;
17
use const PATHINFO_EXTENSION;
18
use function array_filter;
19
use function chmod;
20
use function clearstatcache;
21
use function fileperms;
22
use function filetype;
23
use function finfo_close;
24
use function finfo_file;
25
use function finfo_open;
26
use function function_exists;
27
use function is_dir;
28
use function octdec;
29
use function pathinfo;
30
use function preg_match;
31
use function scandir;
32
use function sprintf;
33
use function substr;
34
use function unlink;
35
use function reset;
36
37
class Filesystem
38
{
39
    /**
40
     * Permissions
41
     *
42
     * @var array
43
     */
44
    protected static $permissions = [
45
        'file' => [
46
            'public'  => 0644,
47
            'private' => 0600,
48
        ],
49
        'dir'  => [
50
            'public'  => 0755,
51
            'private' => 0700,
52
        ],
53
    ];
54
55
    /**
56
     * Mime type list
57
     *
58
     * @var array
59
     */
60
    public static $mime_types = [
61
        '1km' => 'application/vnd.1000minds.decision-model+xml',
62
        '3dml' => 'text/vnd.in3d.3dml',
63
        '3ds' => 'image/x-3ds',
64
        '3g2' => 'video/3gpp2',
65
        '3gp' => 'video/3gp',
66
        '3gpp' => 'video/3gpp',
67
        '3mf' => 'model/3mf',
68
        '7z' => 'application/x-7z-compressed',
69
        '7zip' => 'application/x-7z-compressed',
70
        '123' => 'application/vnd.lotus-1-2-3',
71
        'aab' => 'application/x-authorware-bin',
72
        'aac' => 'audio/x-acc',
73
        'aam' => 'application/x-authorware-map',
74
        'aas' => 'application/x-authorware-seg',
75
        'abw' => 'application/x-abiword',
76
        'ac' => 'application/vnd.nokia.n-gage.ac+xml',
77
        'ac3' => 'audio/ac3',
78
        'acc' => 'application/vnd.americandynamics.acc',
79
        'ace' => 'application/x-ace-compressed',
80
        'acu' => 'application/vnd.acucobol',
81
        'acutc' => 'application/vnd.acucorp',
82
        'adp' => 'audio/adpcm',
83
        'aep' => 'application/vnd.audiograph',
84
        'afm' => 'application/x-font-type1',
85
        'afp' => 'application/vnd.ibm.modcap',
86
        'ahead' => 'application/vnd.ahead.space',
87
        'ai' => 'application/pdf',
88
        'aif' => 'audio/x-aiff',
89
        'aifc' => 'audio/x-aiff',
90
        'aiff' => 'audio/x-aiff',
91
        'air' => 'application/vnd.adobe.air-application-installer-package+zip',
92
        'ait' => 'application/vnd.dvb.ait',
93
        'ami' => 'application/vnd.amiga.ami',
94
        'apk' => 'application/vnd.android.package-archive',
95
        'apng' => 'image/apng',
96
        'appcache' => 'text/cache-manifest',
97
        'application' => 'application/x-ms-application',
98
        'apr' => 'application/vnd.lotus-approach',
99
        'arc' => 'application/x-freearc',
100
        'arj' => 'application/x-arj',
101
        'asc' => 'application/pgp-signature',
102
        'asf' => 'video/x-ms-asf',
103
        'asm' => 'text/x-asm',
104
        'aso' => 'application/vnd.accpac.simply.aso',
105
        'asx' => 'video/x-ms-asf',
106
        'atc' => 'application/vnd.acucorp',
107
        'atom' => 'application/atom+xml',
108
        'atomcat' => 'application/atomcat+xml',
109
        'atomdeleted' => 'application/atomdeleted+xml',
110
        'atomsvc' => 'application/atomsvc+xml',
111
        'atx' => 'application/vnd.antix.game-component',
112
        'au' => 'audio/x-au',
113
        'avi' => 'video/x-msvideo',
114
        'avif' => 'image/avif',
115
        'aw' => 'application/applixware',
116
        'azf' => 'application/vnd.airzip.filesecure.azf',
117
        'azs' => 'application/vnd.airzip.filesecure.azs',
118
        'azv' => 'image/vnd.airzip.accelerator.azv',
119
        'azw' => 'application/vnd.amazon.ebook',
120
        'bat' => 'application/x-msdownload',
121
        'bcpio' => 'application/x-bcpio',
122
        'bdf' => 'application/x-font-bdf',
123
        'bdm' => 'application/vnd.syncml.dm+wbxml',
124
        'bdoc' => 'application/x-bdoc',
125
        'bed' => 'application/vnd.realvnc.bed',
126
        'bh2' => 'application/vnd.fujitsu.oasysprs',
127
        'bin' => 'application/octet-stream',
128
        'blb' => 'application/x-blorb',
129
        'blorb' => 'application/x-blorb',
130
        'bmi' => 'application/vnd.bmi',
131
        'bmml' => 'application/vnd.balsamiq.bmml+xml',
132
        'bmp' => 'image/bmp',
133
        'book' => 'application/vnd.framemaker',
134
        'box' => 'application/vnd.previewsystems.box',
135
        'boz' => 'application/x-bzip2',
136
        'bpk' => 'application/octet-stream',
137
        'bpmn' => 'application/octet-stream',
138
        'bsp' => 'model/vnd.valve.source.compiled-map',
139
        'btif' => 'image/prs.btif',
140
        'buffer' => 'application/octet-stream',
141
        'bz' => 'application/x-bzip',
142
        'bz2' => 'application/x-bzip2',
143
        'c' => 'text/x-c',
144
        'c4d' => 'application/vnd.clonk.c4group',
145
        'c4f' => 'application/vnd.clonk.c4group',
146
        'c4g' => 'application/vnd.clonk.c4group',
147
        'c4p' => 'application/vnd.clonk.c4group',
148
        'c4u' => 'application/vnd.clonk.c4group',
149
        'c11amc' => 'application/vnd.cluetrust.cartomobile-config',
150
        'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg',
151
        'cab' => 'application/vnd.ms-cab-compressed',
152
        'caf' => 'audio/x-caf',
153
        'cap' => 'application/vnd.tcpdump.pcap',
154
        'car' => 'application/vnd.curl.car',
155
        'cat' => 'application/vnd.ms-pki.seccat',
156
        'cb7' => 'application/x-cbr',
157
        'cba' => 'application/x-cbr',
158
        'cbr' => 'application/x-cbr',
159
        'cbt' => 'application/x-cbr',
160
        'cbz' => 'application/x-cbr',
161
        'cc' => 'text/x-c',
162
        'cco' => 'application/x-cocoa',
163
        'cct' => 'application/x-director',
164
        'ccxml' => 'application/ccxml+xml',
165
        'cdbcmsg' => 'application/vnd.contact.cmsg',
166
        'cdf' => 'application/x-netcdf',
167
        'cdfx' => 'application/cdfx+xml',
168
        'cdkey' => 'application/vnd.mediastation.cdkey',
169
        'cdmia' => 'application/cdmi-capability',
170
        'cdmic' => 'application/cdmi-container',
171
        'cdmid' => 'application/cdmi-domain',
172
        'cdmio' => 'application/cdmi-object',
173
        'cdmiq' => 'application/cdmi-queue',
174
        'cdr' => 'application/cdr',
175
        'cdx' => 'chemical/x-cdx',
176
        'cdxml' => 'application/vnd.chemdraw+xml',
177
        'cdy' => 'application/vnd.cinderella',
178
        'cer' => 'application/pkix-cert',
179
        'cfs' => 'application/x-cfs-compressed',
180
        'cgm' => 'image/cgm',
181
        'chat' => 'application/x-chat',
182
        'chm' => 'application/vnd.ms-htmlhelp',
183
        'chrt' => 'application/vnd.kde.kchart',
184
        'cif' => 'chemical/x-cif',
185
        'cii' => 'application/vnd.anser-web-certificate-issue-initiation',
186
        'cil' => 'application/vnd.ms-artgalry',
187
        'cjs' => 'application/node',
188
        'cla' => 'application/vnd.claymore',
189
        'class' => 'application/octet-stream',
190
        'clkk' => 'application/vnd.crick.clicker.keyboard',
191
        'clkp' => 'application/vnd.crick.clicker.palette',
192
        'clkt' => 'application/vnd.crick.clicker.template',
193
        'clkw' => 'application/vnd.crick.clicker.wordbank',
194
        'clkx' => 'application/vnd.crick.clicker',
195
        'clp' => 'application/x-msclip',
196
        'cmc' => 'application/vnd.cosmocaller',
197
        'cmdf' => 'chemical/x-cmdf',
198
        'cml' => 'chemical/x-cml',
199
        'cmp' => 'application/vnd.yellowriver-custom-menu',
200
        'cmx' => 'image/x-cmx',
201
        'cod' => 'application/vnd.rim.cod',
202
        'coffee' => 'text/coffeescript',
203
        'com' => 'application/x-msdownload',
204
        'conf' => 'text/plain',
205
        'cpio' => 'application/x-cpio',
206
        'cpp' => 'text/x-c',
207
        'cpt' => 'application/mac-compactpro',
208
        'crd' => 'application/x-mscardfile',
209
        'crl' => 'application/pkix-crl',
210
        'crt' => 'application/x-x509-ca-cert',
211
        'crx' => 'application/x-chrome-extension',
212
        'cryptonote' => 'application/vnd.rig.cryptonote',
213
        'csh' => 'application/x-csh',
214
        'csl' => 'application/vnd.citationstyles.style+xml',
215
        'csml' => 'chemical/x-csml',
216
        'csp' => 'application/vnd.commonspace',
217
        'csr' => 'application/octet-stream',
218
        'css' => 'text/css',
219
        'cst' => 'application/x-director',
220
        'csv' => 'text/csv',
221
        'cu' => 'application/cu-seeme',
222
        'curl' => 'text/vnd.curl',
223
        'cww' => 'application/prs.cww',
224
        'cxt' => 'application/x-director',
225
        'cxx' => 'text/x-c',
226
        'dae' => 'model/vnd.collada+xml',
227
        'daf' => 'application/vnd.mobius.daf',
228
        'dart' => 'application/vnd.dart',
229
        'dataless' => 'application/vnd.fdsn.seed',
230
        'davmount' => 'application/davmount+xml',
231
        'dbk' => 'application/docbook+xml',
232
        'dcr' => 'application/x-director',
233
        'dcurl' => 'text/vnd.curl.dcurl',
234
        'dd2' => 'application/vnd.oma.dd2+xml',
235
        'ddd' => 'application/vnd.fujixerox.ddd',
236
        'ddf' => 'application/vnd.syncml.dmddf+xml',
237
        'dds' => 'image/vnd.ms-dds',
238
        'deb' => 'application/x-debian-package',
239
        'def' => 'text/plain',
240
        'deploy' => 'application/octet-stream',
241
        'der' => 'application/x-x509-ca-cert',
242
        'dfac' => 'application/vnd.dreamfactory',
243
        'dgc' => 'application/x-dgc-compressed',
244
        'dic' => 'text/x-c',
245
        'dir' => 'application/x-director',
246
        'dis' => 'application/vnd.mobius.dis',
247
        'disposition-notification' => 'message/disposition-notification',
248
        'dist' => 'application/octet-stream',
249
        'distz' => 'application/octet-stream',
250
        'djv' => 'image/vnd.djvu',
251
        'djvu' => 'image/vnd.djvu',
252
        'dll' => 'application/octet-stream',
253
        'dmg' => 'application/x-apple-diskimage',
254
        'dmn' => 'application/octet-stream',
255
        'dmp' => 'application/vnd.tcpdump.pcap',
256
        'dms' => 'application/octet-stream',
257
        'dna' => 'application/vnd.dna',
258
        'doc' => 'application/msword',
259
        'docm' => 'application/vnd.ms-word.template.macroEnabled.12',
260
        'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
261
        'dot' => 'application/msword',
262
        'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
263
        'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
264
        'dp' => 'application/vnd.osgi.dp',
265
        'dpg' => 'application/vnd.dpgraph',
266
        'dra' => 'audio/vnd.dra',
267
        'drle' => 'image/dicom-rle',
268
        'dsc' => 'text/prs.lines.tag',
269
        'dssc' => 'application/dssc+der',
270
        'dtb' => 'application/x-dtbook+xml',
271
        'dtd' => 'application/xml-dtd',
272
        'dts' => 'audio/vnd.dts',
273
        'dtshd' => 'audio/vnd.dts.hd',
274
        'dump' => 'application/octet-stream',
275
        'dvb' => 'video/vnd.dvb.file',
276
        'dvi' => 'application/x-dvi',
277
        'dwd' => 'application/atsc-dwd+xml',
278
        'dwf' => 'model/vnd.dwf',
279
        'dwg' => 'image/vnd.dwg',
280
        'dxf' => 'image/vnd.dxf',
281
        'dxp' => 'application/vnd.spotfire.dxp',
282
        'dxr' => 'application/x-director',
283
        'ear' => 'application/java-archive',
284
        'ecelp4800' => 'audio/vnd.nuera.ecelp4800',
285
        'ecelp7470' => 'audio/vnd.nuera.ecelp7470',
286
        'ecelp9600' => 'audio/vnd.nuera.ecelp9600',
287
        'ecma' => 'application/ecmascript',
288
        'edm' => 'application/vnd.novadigm.edm',
289
        'edx' => 'application/vnd.novadigm.edx',
290
        'efif' => 'application/vnd.picsel',
291
        'ei6' => 'application/vnd.pg.osasli',
292
        'elc' => 'application/octet-stream',
293
        'emf' => 'image/emf',
294
        'eml' => 'message/rfc822',
295
        'emma' => 'application/emma+xml',
296
        'emotionml' => 'application/emotionml+xml',
297
        'emz' => 'application/x-msmetafile',
298
        'eol' => 'audio/vnd.digital-winds',
299
        'eot' => 'application/vnd.ms-fontobject',
300
        'eps' => 'application/postscript',
301
        'epub' => 'application/epub+zip',
302
        'es' => 'application/ecmascript',
303
        'es3' => 'application/vnd.eszigno3+xml',
304
        'esa' => 'application/vnd.osgi.subsystem',
305
        'esf' => 'application/vnd.epson.esf',
306
        'et3' => 'application/vnd.eszigno3+xml',
307
        'etx' => 'text/x-setext',
308
        'eva' => 'application/x-eva',
309
        'evy' => 'application/x-envoy',
310
        'exe' => 'application/octet-stream',
311
        'exi' => 'application/exi',
312
        'exr' => 'image/aces',
313
        'ext' => 'application/vnd.novadigm.ext',
314
        'ez' => 'application/andrew-inset',
315
        'ez2' => 'application/vnd.ezpix-album',
316
        'ez3' => 'application/vnd.ezpix-package',
317
        'f' => 'text/x-fortran',
318
        'f4v' => 'video/mp4',
319
        'f77' => 'text/x-fortran',
320
        'f90' => 'text/x-fortran',
321
        'fbs' => 'image/vnd.fastbidsheet',
322
        'fcdt' => 'application/vnd.adobe.formscentral.fcdt',
323
        'fcs' => 'application/vnd.isac.fcs',
324
        'fdf' => 'application/vnd.fdf',
325
        'fdt' => 'application/fdt+xml',
326
        'fe_launch' => 'application/vnd.denovo.fcselayout-link',
327
        'fg5' => 'application/vnd.fujitsu.oasysgp',
328
        'fgd' => 'application/x-director',
329
        'fh' => 'image/x-freehand',
330
        'fh4' => 'image/x-freehand',
331
        'fh5' => 'image/x-freehand',
332
        'fh7' => 'image/x-freehand',
333
        'fhc' => 'image/x-freehand',
334
        'fig' => 'application/x-xfig',
335
        'fits' => 'image/fits',
336
        'flac' => 'audio/x-flac',
337
        'fli' => 'video/x-fli',
338
        'flo' => 'application/vnd.micrografx.flo',
339
        'flv' => 'video/x-flv',
340
        'flw' => 'application/vnd.kde.kivio',
341
        'flx' => 'text/vnd.fmi.flexstor',
342
        'fly' => 'text/vnd.fly',
343
        'fm' => 'application/vnd.framemaker',
344
        'fnc' => 'application/vnd.frogans.fnc',
345
        'fo' => 'application/vnd.software602.filler.form+xml',
346
        'for' => 'text/x-fortran',
347
        'fpx' => 'image/vnd.fpx',
348
        'frame' => 'application/vnd.framemaker',
349
        'fsc' => 'application/vnd.fsc.weblaunch',
350
        'fst' => 'image/vnd.fst',
351
        'ftc' => 'application/vnd.fluxtime.clip',
352
        'fti' => 'application/vnd.anser-web-funds-transfer-initiation',
353
        'fvt' => 'video/vnd.fvt',
354
        'fxp' => 'application/vnd.adobe.fxp',
355
        'fxpl' => 'application/vnd.adobe.fxp',
356
        'fzs' => 'application/vnd.fuzzysheet',
357
        'g2w' => 'application/vnd.geoplan',
358
        'g3' => 'image/g3fax',
359
        'g3w' => 'application/vnd.geospace',
360
        'gac' => 'application/vnd.groove-account',
361
        'gam' => 'application/x-tads',
362
        'gbr' => 'application/rpki-ghostbusters',
363
        'gca' => 'application/x-gca-compressed',
364
        'gdl' => 'model/vnd.gdl',
365
        'gdoc' => 'application/vnd.google-apps.document',
366
        'geo' => 'application/vnd.dynageo',
367
        'geojson' => 'application/geo+json',
368
        'gex' => 'application/vnd.geometry-explorer',
369
        'ggb' => 'application/vnd.geogebra.file',
370
        'ggt' => 'application/vnd.geogebra.tool',
371
        'ghf' => 'application/vnd.groove-help',
372
        'gif' => 'image/gif',
373
        'gim' => 'application/vnd.groove-identity-message',
374
        'glb' => 'model/gltf-binary',
375
        'gltf' => 'model/gltf+json',
376
        'gml' => 'application/gml+xml',
377
        'gmx' => 'application/vnd.gmx',
378
        'gnumeric' => 'application/x-gnumeric',
379
        'gpg' => 'application/gpg-keys',
380
        'gph' => 'application/vnd.flographit',
381
        'gpx' => 'application/gpx+xml',
382
        'gqf' => 'application/vnd.grafeq',
383
        'gqs' => 'application/vnd.grafeq',
384
        'gram' => 'application/srgs',
385
        'gramps' => 'application/x-gramps-xml',
386
        'gre' => 'application/vnd.geometry-explorer',
387
        'grv' => 'application/vnd.groove-injector',
388
        'grxml' => 'application/srgs+xml',
389
        'gsf' => 'application/x-font-ghostscript',
390
        'gsheet' => 'application/vnd.google-apps.spreadsheet',
391
        'gslides' => 'application/vnd.google-apps.presentation',
392
        'gtar' => 'application/x-gtar',
393
        'gtm' => 'application/vnd.groove-tool-message',
394
        'gtw' => 'model/vnd.gtw',
395
        'gv' => 'text/vnd.graphviz',
396
        'gxf' => 'application/gxf',
397
        'gxt' => 'application/vnd.geonext',
398
        'gz' => 'application/x-gzip',
399
        'gzip' => 'application/x-gzip',
400
        'h' => 'text/x-c',
401
        'h261' => 'video/h261',
402
        'h263' => 'video/h263',
403
        'h264' => 'video/h264',
404
        'hal' => 'application/vnd.hal+xml',
405
        'hbci' => 'application/vnd.hbci',
406
        'hbs' => 'text/x-handlebars-template',
407
        'hdd' => 'application/x-virtualbox-hdd',
408
        'hdf' => 'application/x-hdf',
409
        'heic' => 'image/heic',
410
        'heics' => 'image/heic-sequence',
411
        'heif' => 'image/heif',
412
        'heifs' => 'image/heif-sequence',
413
        'hej2' => 'image/hej2k',
414
        'held' => 'application/atsc-held+xml',
415
        'hh' => 'text/x-c',
416
        'hjson' => 'application/hjson',
417
        'hlp' => 'application/winhlp',
418
        'hpgl' => 'application/vnd.hp-hpgl',
419
        'hpid' => 'application/vnd.hp-hpid',
420
        'hps' => 'application/vnd.hp-hps',
421
        'hqx' => 'application/mac-binhex40',
422
        'hsj2' => 'image/hsj2',
423
        'htc' => 'text/x-component',
424
        'htke' => 'application/vnd.kenameaapp',
425
        'htm' => 'text/html',
426
        'html' => 'text/html',
427
        'hvd' => 'application/vnd.yamaha.hv-dic',
428
        'hvp' => 'application/vnd.yamaha.hv-voice',
429
        'hvs' => 'application/vnd.yamaha.hv-script',
430
        'i2g' => 'application/vnd.intergeo',
431
        'icc' => 'application/vnd.iccprofile',
432
        'ice' => 'x-conference/x-cooltalk',
433
        'icm' => 'application/vnd.iccprofile',
434
        'ico' => 'image/x-icon',
435
        'ics' => 'text/calendar',
436
        'ief' => 'image/ief',
437
        'ifb' => 'text/calendar',
438
        'ifm' => 'application/vnd.shana.informed.formdata',
439
        'iges' => 'model/iges',
440
        'igl' => 'application/vnd.igloader',
441
        'igm' => 'application/vnd.insors.igm',
442
        'igs' => 'model/iges',
443
        'igx' => 'application/vnd.micrografx.igx',
444
        'iif' => 'application/vnd.shana.informed.interchange',
445
        'img' => 'application/octet-stream',
446
        'imp' => 'application/vnd.accpac.simply.imp',
447
        'ims' => 'application/vnd.ms-ims',
448
        'in' => 'text/plain',
449
        'ini' => 'text/plain',
450
        'ink' => 'application/inkml+xml',
451
        'inkml' => 'application/inkml+xml',
452
        'install' => 'application/x-install-instructions',
453
        'iota' => 'application/vnd.astraea-software.iota',
454
        'ipfix' => 'application/ipfix',
455
        'ipk' => 'application/vnd.shana.informed.package',
456
        'irm' => 'application/vnd.ibm.rights-management',
457
        'irp' => 'application/vnd.irepository.package+xml',
458
        'iso' => 'application/x-iso9660-image',
459
        'itp' => 'application/vnd.shana.informed.formtemplate',
460
        'its' => 'application/its+xml',
461
        'ivp' => 'application/vnd.immervision-ivp',
462
        'ivu' => 'application/vnd.immervision-ivu',
463
        'jad' => 'text/vnd.sun.j2me.app-descriptor',
464
        'jade' => 'text/jade',
465
        'jam' => 'application/vnd.jam',
466
        'jar' => 'application/java-archive',
467
        'jardiff' => 'application/x-java-archive-diff',
468
        'java' => 'text/x-java-source',
469
        'jhc' => 'image/jphc',
470
        'jisp' => 'application/vnd.jisp',
471
        'jls' => 'image/jls',
472
        'jlt' => 'application/vnd.hp-jlyt',
473
        'jng' => 'image/x-jng',
474
        'jnlp' => 'application/x-java-jnlp-file',
475
        'joda' => 'application/vnd.joost.joda-archive',
476
        'jp2' => 'image/jp2',
477
        'jpe' => 'image/jpeg',
478
        'jpeg' => 'image/jpeg',
479
        'jpf' => 'image/jpx',
480
        'jpg' => 'image/jpeg',
481
        'jpg2' => 'image/jp2',
482
        'jpgm' => 'video/jpm',
483
        'jpgv' => 'video/jpeg',
484
        'jph' => 'image/jph',
485
        'jpm' => 'video/jpm',
486
        'jpx' => 'image/jpx',
487
        'js' => 'application/javascript',
488
        'json' => 'application/json',
489
        'json5' => 'application/json5',
490
        'jsonld' => 'application/ld+json',
491
        'jsonml' => 'application/jsonml+json',
492
        'jsx' => 'text/jsx',
493
        'jxr' => 'image/jxr',
494
        'jxra' => 'image/jxra',
495
        'jxrs' => 'image/jxrs',
496
        'jxs' => 'image/jxs',
497
        'jxsc' => 'image/jxsc',
498
        'jxsi' => 'image/jxsi',
499
        'jxss' => 'image/jxss',
500
        'kar' => 'audio/midi',
501
        'karbon' => 'application/vnd.kde.karbon',
502
        'kdb' => 'application/octet-stream',
503
        'kdbx' => 'application/x-keepass2',
504
        'key' => 'application/vnd.apple.keynote',
505
        'kfo' => 'application/vnd.kde.kformula',
506
        'kia' => 'application/vnd.kidspiration',
507
        'kml' => 'application/vnd.google-earth.kml+xml',
508
        'kmz' => 'application/vnd.google-earth.kmz',
509
        'kne' => 'application/vnd.kinar',
510
        'knp' => 'application/vnd.kinar',
511
        'kon' => 'application/vnd.kde.kontour',
512
        'kpr' => 'application/vnd.kde.kpresenter',
513
        'kpt' => 'application/vnd.kde.kpresenter',
514
        'kpxx' => 'application/vnd.ds-keypoint',
515
        'ksp' => 'application/vnd.kde.kspread',
516
        'ktr' => 'application/vnd.kahootz',
517
        'ktx' => 'image/ktx',
518
        'ktz' => 'application/vnd.kahootz',
519
        'kwd' => 'application/vnd.kde.kword',
520
        'kwt' => 'application/vnd.kde.kword',
521
        'lasxml' => 'application/vnd.las.las+xml',
522
        'latex' => 'application/x-latex',
523
        'lbd' => 'application/vnd.llamagraphics.life-balance.desktop',
524
        'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml',
525
        'les' => 'application/vnd.hhe.lesson-player',
526
        'less' => 'text/less',
527
        'lgr' => 'application/lgr+xml',
528
        'lha' => 'application/octet-stream',
529
        'link66' => 'application/vnd.route66.link66+xml',
530
        'list' => 'text/plain',
531
        'list3820' => 'application/vnd.ibm.modcap',
532
        'listafp' => 'application/vnd.ibm.modcap',
533
        'litcoffee' => 'text/coffeescript',
534
        'lnk' => 'application/x-ms-shortcut',
535
        'log' => 'text/plain',
536
        'lostxml' => 'application/lost+xml',
537
        'lrf' => 'application/octet-stream',
538
        'lrm' => 'application/vnd.ms-lrm',
539
        'ltf' => 'application/vnd.frogans.ltf',
540
        'lua' => 'text/x-lua',
541
        'luac' => 'application/x-lua-bytecode',
542
        'lvp' => 'audio/vnd.lucent.voice',
543
        'lwp' => 'application/vnd.lotus-wordpro',
544
        'lzh' => 'application/octet-stream',
545
        'm1v' => 'video/mpeg',
546
        'm2a' => 'audio/mpeg',
547
        'm2v' => 'video/mpeg',
548
        'm3a' => 'audio/mpeg',
549
        'm3u' => 'text/plain',
550
        'm3u8' => 'application/vnd.apple.mpegurl',
551
        'm4a' => 'audio/x-m4a',
552
        'm4p' => 'application/mp4',
553
        'm4u' => 'application/vnd.mpegurl',
554
        'm4v' => 'video/x-m4v',
555
        'm13' => 'application/x-msmediaview',
556
        'm14' => 'application/x-msmediaview',
557
        'm21' => 'application/mp21',
558
        'ma' => 'application/mathematica',
559
        'mads' => 'application/mads+xml',
560
        'maei' => 'application/mmt-aei+xml',
561
        'mag' => 'application/vnd.ecowin.chart',
562
        'maker' => 'application/vnd.framemaker',
563
        'man' => 'text/troff',
564
        'manifest' => 'text/cache-manifest',
565
        'map' => 'application/json',
566
        'mar' => 'application/octet-stream',
567
        'markdown' => 'text/markdown',
568
        'mathml' => 'application/mathml+xml',
569
        'mb' => 'application/mathematica',
570
        'mbk' => 'application/vnd.mobius.mbk',
571
        'mbox' => 'application/mbox',
572
        'mc1' => 'application/vnd.medcalcdata',
573
        'mcd' => 'application/vnd.mcd',
574
        'mcurl' => 'text/vnd.curl.mcurl',
575
        'md' => 'text/markdown',
576
        'mdb' => 'application/x-msaccess',
577
        'mdi' => 'image/vnd.ms-modi',
578
        'mdx' => 'text/mdx',
579
        'me' => 'text/troff',
580
        'mesh' => 'model/mesh',
581
        'meta4' => 'application/metalink4+xml',
582
        'metalink' => 'application/metalink+xml',
583
        'mets' => 'application/mets+xml',
584
        'mfm' => 'application/vnd.mfmp',
585
        'mft' => 'application/rpki-manifest',
586
        'mgp' => 'application/vnd.osgeo.mapguide.package',
587
        'mgz' => 'application/vnd.proteus.magazine',
588
        'mid' => 'audio/midi',
589
        'midi' => 'audio/midi',
590
        'mie' => 'application/x-mie',
591
        'mif' => 'application/vnd.mif',
592
        'mime' => 'message/rfc822',
593
        'mj2' => 'video/mj2',
594
        'mjp2' => 'video/mj2',
595
        'mjs' => 'application/javascript',
596
        'mk3d' => 'video/x-matroska',
597
        'mka' => 'audio/x-matroska',
598
        'mkd' => 'text/x-markdown',
599
        'mks' => 'video/x-matroska',
600
        'mkv' => 'video/x-matroska',
601
        'mlp' => 'application/vnd.dolby.mlp',
602
        'mmd' => 'application/vnd.chipnuts.karaoke-mmd',
603
        'mmf' => 'application/vnd.smaf',
604
        'mml' => 'text/mathml',
605
        'mmr' => 'image/vnd.fujixerox.edmics-mmr',
606
        'mng' => 'video/x-mng',
607
        'mny' => 'application/x-msmoney',
608
        'mobi' => 'application/x-mobipocket-ebook',
609
        'mods' => 'application/mods+xml',
610
        'mov' => 'video/quicktime',
611
        'movie' => 'video/x-sgi-movie',
612
        'mp2' => 'audio/mpeg',
613
        'mp2a' => 'audio/mpeg',
614
        'mp3' => 'audio/mpeg',
615
        'mp4' => 'video/mp4',
616
        'mp4a' => 'audio/mp4',
617
        'mp4s' => 'application/mp4',
618
        'mp4v' => 'video/mp4',
619
        'mp21' => 'application/mp21',
620
        'mpc' => 'application/vnd.mophun.certificate',
621
        'mpd' => 'application/dash+xml',
622
        'mpe' => 'video/mpeg',
623
        'mpeg' => 'video/mpeg',
624
        'mpg' => 'video/mpeg',
625
        'mpg4' => 'video/mp4',
626
        'mpga' => 'audio/mpeg',
627
        'mpkg' => 'application/vnd.apple.installer+xml',
628
        'mpm' => 'application/vnd.blueice.multipass',
629
        'mpn' => 'application/vnd.mophun.application',
630
        'mpp' => 'application/vnd.ms-project',
631
        'mpt' => 'application/vnd.ms-project',
632
        'mpy' => 'application/vnd.ibm.minipay',
633
        'mqy' => 'application/vnd.mobius.mqy',
634
        'mrc' => 'application/marc',
635
        'mrcx' => 'application/marcxml+xml',
636
        'ms' => 'text/troff',
637
        'mscml' => 'application/mediaservercontrol+xml',
638
        'mseed' => 'application/vnd.fdsn.mseed',
639
        'mseq' => 'application/vnd.mseq',
640
        'msf' => 'application/vnd.epson.msf',
641
        'msg' => 'application/vnd.ms-outlook',
642
        'msh' => 'model/mesh',
643
        'msi' => 'application/x-msdownload',
644
        'msl' => 'application/vnd.mobius.msl',
645
        'msm' => 'application/octet-stream',
646
        'msp' => 'application/octet-stream',
647
        'msty' => 'application/vnd.muvee.style',
648
        'mtl' => 'model/mtl',
649
        'mts' => 'model/vnd.mts',
650
        'mus' => 'application/vnd.musician',
651
        'musd' => 'application/mmt-usd+xml',
652
        'musicxml' => 'application/vnd.recordare.musicxml+xml',
653
        'mvb' => 'application/x-msmediaview',
654
        'mwf' => 'application/vnd.mfer',
655
        'mxf' => 'application/mxf',
656
        'mxl' => 'application/vnd.recordare.musicxml',
657
        'mxmf' => 'audio/mobile-xmf',
658
        'mxml' => 'application/xv+xml',
659
        'mxs' => 'application/vnd.triscape.mxs',
660
        'mxu' => 'video/vnd.mpegurl',
661
        'n-gage' => 'application/vnd.nokia.n-gage.symbian.install',
662
        'n3' => 'text/n3',
663
        'nb' => 'application/mathematica',
664
        'nbp' => 'application/vnd.wolfram.player',
665
        'nc' => 'application/x-netcdf',
666
        'ncx' => 'application/x-dtbncx+xml',
667
        'nfo' => 'text/x-nfo',
668
        'ngdat' => 'application/vnd.nokia.n-gage.data',
669
        'nitf' => 'application/vnd.nitf',
670
        'nlu' => 'application/vnd.neurolanguage.nlu',
671
        'nml' => 'application/vnd.enliven',
672
        'nnd' => 'application/vnd.noblenet-directory',
673
        'nns' => 'application/vnd.noblenet-sealer',
674
        'nnw' => 'application/vnd.noblenet-web',
675
        'npx' => 'image/vnd.net-fpx',
676
        'nq' => 'application/n-quads',
677
        'nsc' => 'application/x-conference',
678
        'nsf' => 'application/vnd.lotus-notes',
679
        'nt' => 'application/n-triples',
680
        'ntf' => 'application/vnd.nitf',
681
        'numbers' => 'application/vnd.apple.numbers',
682
        'nzb' => 'application/x-nzb',
683
        'oa2' => 'application/vnd.fujitsu.oasys2',
684
        'oa3' => 'application/vnd.fujitsu.oasys3',
685
        'oas' => 'application/vnd.fujitsu.oasys',
686
        'obd' => 'application/x-msbinder',
687
        'obgx' => 'application/vnd.openblox.game+xml',
688
        'obj' => 'model/obj',
689
        'oda' => 'application/oda',
690
        'odb' => 'application/vnd.oasis.opendocument.database',
691
        'odc' => 'application/vnd.oasis.opendocument.chart',
692
        'odf' => 'application/vnd.oasis.opendocument.formula',
693
        'odft' => 'application/vnd.oasis.opendocument.formula-template',
694
        'odg' => 'application/vnd.oasis.opendocument.graphics',
695
        'odi' => 'application/vnd.oasis.opendocument.image',
696
        'odm' => 'application/vnd.oasis.opendocument.text-master',
697
        'odp' => 'application/vnd.oasis.opendocument.presentation',
698
        'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
699
        'odt' => 'application/vnd.oasis.opendocument.text',
700
        'oga' => 'audio/ogg',
701
        'ogex' => 'model/vnd.opengex',
702
        'ogg' => 'audio/ogg',
703
        'ogv' => 'video/ogg',
704
        'ogx' => 'application/ogg',
705
        'omdoc' => 'application/omdoc+xml',
706
        'onepkg' => 'application/onenote',
707
        'onetmp' => 'application/onenote',
708
        'onetoc' => 'application/onenote',
709
        'onetoc2' => 'application/onenote',
710
        'opf' => 'application/oebps-package+xml',
711
        'opml' => 'text/x-opml',
712
        'oprc' => 'application/vnd.palm',
713
        'org' => 'text/x-org',
714
        'osf' => 'application/vnd.yamaha.openscoreformat',
715
        'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',
716
        'osm' => 'application/vnd.openstreetmap.data+xml',
717
        'otc' => 'application/vnd.oasis.opendocument.chart-template',
718
        'otf' => 'font/otf',
719
        'otg' => 'application/vnd.oasis.opendocument.graphics-template',
720
        'oth' => 'application/vnd.oasis.opendocument.text-web',
721
        'oti' => 'application/vnd.oasis.opendocument.image-template',
722
        'otp' => 'application/vnd.oasis.opendocument.presentation-template',
723
        'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
724
        'ott' => 'application/vnd.oasis.opendocument.text-template',
725
        'ova' => 'application/x-virtualbox-ova',
726
        'ovf' => 'application/x-virtualbox-ovf',
727
        'owl' => 'application/rdf+xml',
728
        'oxps' => 'application/oxps',
729
        'oxt' => 'application/vnd.openofficeorg.extension',
730
        'p' => 'text/x-pascal',
731
        'p7a' => 'application/x-pkcs7-signature',
732
        'p7b' => 'application/x-pkcs7-certificates',
733
        'p7c' => 'application/pkcs7-mime',
734
        'p7m' => 'application/pkcs7-mime',
735
        'p7r' => 'application/x-pkcs7-certreqresp',
736
        'p7s' => 'application/pkcs7-signature',
737
        'p8' => 'application/pkcs8',
738
        'p10' => 'application/x-pkcs10',
739
        'p12' => 'application/x-pkcs12',
740
        'pac' => 'application/x-ns-proxy-autoconfig',
741
        'pages' => 'application/vnd.apple.pages',
742
        'pas' => 'text/x-pascal',
743
        'paw' => 'application/vnd.pawaafile',
744
        'pbd' => 'application/vnd.powerbuilder6',
745
        'pbm' => 'image/x-portable-bitmap',
746
        'pcap' => 'application/vnd.tcpdump.pcap',
747
        'pcf' => 'application/x-font-pcf',
748
        'pcl' => 'application/vnd.hp-pcl',
749
        'pclxl' => 'application/vnd.hp-pclxl',
750
        'pct' => 'image/x-pict',
751
        'pcurl' => 'application/vnd.curl.pcurl',
752
        'pcx' => 'image/x-pcx',
753
        'pdb' => 'application/x-pilot',
754
        'pde' => 'text/x-processing',
755
        'pdf' => 'application/pdf',
756
        'pem' => 'application/x-x509-user-cert',
757
        'pfa' => 'application/x-font-type1',
758
        'pfb' => 'application/x-font-type1',
759
        'pfm' => 'application/x-font-type1',
760
        'pfr' => 'application/font-tdpfr',
761
        'pfx' => 'application/x-pkcs12',
762
        'pgm' => 'image/x-portable-graymap',
763
        'pgn' => 'application/x-chess-pgn',
764
        'pgp' => 'application/pgp',
765
        'php' => 'application/x-httpd-php',
766
        'php3' => 'application/x-httpd-php',
767
        'php4' => 'application/x-httpd-php',
768
        'phps' => 'application/x-httpd-php-source',
769
        'phtml' => 'application/x-httpd-php',
770
        'pic' => 'image/x-pict',
771
        'pkg' => 'application/octet-stream',
772
        'pki' => 'application/pkixcmp',
773
        'pkipath' => 'application/pkix-pkipath',
774
        'pkpass' => 'application/vnd.apple.pkpass',
775
        'pl' => 'application/x-perl',
776
        'plb' => 'application/vnd.3gpp.pic-bw-large',
777
        'plc' => 'application/vnd.mobius.plc',
778
        'plf' => 'application/vnd.pocketlearn',
779
        'pls' => 'application/pls+xml',
780
        'pm' => 'application/x-perl',
781
        'pml' => 'application/vnd.ctc-posml',
782
        'png' => 'image/png',
783
        'pnm' => 'image/x-portable-anymap',
784
        'portpkg' => 'application/vnd.macports.portpkg',
785
        'pot' => 'application/vnd.ms-powerpoint',
786
        'potm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
787
        'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
788
        'ppa' => 'application/vnd.ms-powerpoint',
789
        'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
790
        'ppd' => 'application/vnd.cups-ppd',
791
        'ppm' => 'image/x-portable-pixmap',
792
        'pps' => 'application/vnd.ms-powerpoint',
793
        'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
794
        'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
795
        'ppt' => 'application/powerpoint',
796
        'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
797
        'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
798
        'pqa' => 'application/vnd.palm',
799
        'prc' => 'application/x-pilot',
800
        'pre' => 'application/vnd.lotus-freelance',
801
        'prf' => 'application/pics-rules',
802
        'provx' => 'application/provenance+xml',
803
        'ps' => 'application/postscript',
804
        'psb' => 'application/vnd.3gpp.pic-bw-small',
805
        'psd' => 'application/x-photoshop',
806
        'psf' => 'application/x-font-linux-psf',
807
        'pskcxml' => 'application/pskc+xml',
808
        'pti' => 'image/prs.pti',
809
        'ptid' => 'application/vnd.pvi.ptid1',
810
        'pub' => 'application/x-mspublisher',
811
        'pvb' => 'application/vnd.3gpp.pic-bw-var',
812
        'pwn' => 'application/vnd.3m.post-it-notes',
813
        'pya' => 'audio/vnd.ms-playready.media.pya',
814
        'pyv' => 'video/vnd.ms-playready.media.pyv',
815
        'qam' => 'application/vnd.epson.quickanime',
816
        'qbo' => 'application/vnd.intu.qbo',
817
        'qfx' => 'application/vnd.intu.qfx',
818
        'qps' => 'application/vnd.publishare-delta-tree',
819
        'qt' => 'video/quicktime',
820
        'qwd' => 'application/vnd.quark.quarkxpress',
821
        'qwt' => 'application/vnd.quark.quarkxpress',
822
        'qxb' => 'application/vnd.quark.quarkxpress',
823
        'qxd' => 'application/vnd.quark.quarkxpress',
824
        'qxl' => 'application/vnd.quark.quarkxpress',
825
        'qxt' => 'application/vnd.quark.quarkxpress',
826
        'ra' => 'audio/x-realaudio',
827
        'ram' => 'audio/x-pn-realaudio',
828
        'raml' => 'application/raml+yaml',
829
        'rapd' => 'application/route-apd+xml',
830
        'rar' => 'application/x-rar',
831
        'ras' => 'image/x-cmu-raster',
832
        'rcprofile' => 'application/vnd.ipunplugged.rcprofile',
833
        'rdf' => 'application/rdf+xml',
834
        'rdz' => 'application/vnd.data-vision.rdz',
835
        'relo' => 'application/p2p-overlay+xml',
836
        'rep' => 'application/vnd.businessobjects',
837
        'res' => 'application/x-dtbresource+xml',
838
        'rgb' => 'image/x-rgb',
839
        'rif' => 'application/reginfo+xml',
840
        'rip' => 'audio/vnd.rip',
841
        'ris' => 'application/x-research-info-systems',
842
        'rl' => 'application/resource-lists+xml',
843
        'rlc' => 'image/vnd.fujixerox.edmics-rlc',
844
        'rld' => 'application/resource-lists-diff+xml',
845
        'rm' => 'audio/x-pn-realaudio',
846
        'rmi' => 'audio/midi',
847
        'rmp' => 'audio/x-pn-realaudio-plugin',
848
        'rms' => 'application/vnd.jcp.javame.midlet-rms',
849
        'rmvb' => 'application/vnd.rn-realmedia-vbr',
850
        'rnc' => 'application/relax-ng-compact-syntax',
851
        'rng' => 'application/xml',
852
        'roa' => 'application/rpki-roa',
853
        'roff' => 'text/troff',
854
        'rp9' => 'application/vnd.cloanto.rp9',
855
        'rpm' => 'audio/x-pn-realaudio-plugin',
856
        'rpss' => 'application/vnd.nokia.radio-presets',
857
        'rpst' => 'application/vnd.nokia.radio-preset',
858
        'rq' => 'application/sparql-query',
859
        'rs' => 'application/rls-services+xml',
860
        'rsa' => 'application/x-pkcs7',
861
        'rsat' => 'application/atsc-rsat+xml',
862
        'rsd' => 'application/rsd+xml',
863
        'rsheet' => 'application/urc-ressheet+xml',
864
        'rss' => 'application/rss+xml',
865
        'rtf' => 'text/rtf',
866
        'rtx' => 'text/richtext',
867
        'run' => 'application/x-makeself',
868
        'rusd' => 'application/route-usd+xml',
869
        'rv' => 'video/vnd.rn-realvideo',
870
        's' => 'text/x-asm',
871
        's3m' => 'audio/s3m',
872
        'saf' => 'application/vnd.yamaha.smaf-audio',
873
        'sass' => 'text/x-sass',
874
        'sbml' => 'application/sbml+xml',
875
        'sc' => 'application/vnd.ibm.secure-container',
876
        'scd' => 'application/x-msschedule',
877
        'scm' => 'application/vnd.lotus-screencam',
878
        'scq' => 'application/scvp-cv-request',
879
        'scs' => 'application/scvp-cv-response',
880
        'scss' => 'text/x-scss',
881
        'scurl' => 'text/vnd.curl.scurl',
882
        'sda' => 'application/vnd.stardivision.draw',
883
        'sdc' => 'application/vnd.stardivision.calc',
884
        'sdd' => 'application/vnd.stardivision.impress',
885
        'sdkd' => 'application/vnd.solent.sdkm+xml',
886
        'sdkm' => 'application/vnd.solent.sdkm+xml',
887
        'sdp' => 'application/sdp',
888
        'sdw' => 'application/vnd.stardivision.writer',
889
        'sea' => 'application/octet-stream',
890
        'see' => 'application/vnd.seemail',
891
        'seed' => 'application/vnd.fdsn.seed',
892
        'sema' => 'application/vnd.sema',
893
        'semd' => 'application/vnd.semd',
894
        'semf' => 'application/vnd.semf',
895
        'senmlx' => 'application/senml+xml',
896
        'sensmlx' => 'application/sensml+xml',
897
        'ser' => 'application/java-serialized-object',
898
        'setpay' => 'application/set-payment-initiation',
899
        'setreg' => 'application/set-registration-initiation',
900
        'sfd-hdstx' => 'application/vnd.hydrostatix.sof-data',
901
        'sfs' => 'application/vnd.spotfire.sfs',
902
        'sfv' => 'text/x-sfv',
903
        'sgi' => 'image/sgi',
904
        'sgl' => 'application/vnd.stardivision.writer-global',
905
        'sgm' => 'text/sgml',
906
        'sgml' => 'text/sgml',
907
        'sh' => 'application/x-sh',
908
        'shar' => 'application/x-shar',
909
        'shex' => 'text/shex',
910
        'shf' => 'application/shf+xml',
911
        'shtml' => 'text/html',
912
        'sid' => 'image/x-mrsid-image',
913
        'sieve' => 'application/sieve',
914
        'sig' => 'application/pgp-signature',
915
        'sil' => 'audio/silk',
916
        'silo' => 'model/mesh',
917
        'sis' => 'application/vnd.symbian.install',
918
        'sisx' => 'application/vnd.symbian.install',
919
        'sit' => 'application/x-stuffit',
920
        'sitx' => 'application/x-stuffitx',
921
        'siv' => 'application/sieve',
922
        'skd' => 'application/vnd.koan',
923
        'skm' => 'application/vnd.koan',
924
        'skp' => 'application/vnd.koan',
925
        'skt' => 'application/vnd.koan',
926
        'sldm' => 'application/vnd.ms-powerpoint.slide.macroenabled.12',
927
        'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
928
        'slim' => 'text/slim',
929
        'slm' => 'text/slim',
930
        'sls' => 'application/route-s-tsid+xml',
931
        'slt' => 'application/vnd.epson.salt',
932
        'sm' => 'application/vnd.stepmania.stepchart',
933
        'smf' => 'application/vnd.stardivision.math',
934
        'smi' => 'application/smil',
935
        'smil' => 'application/smil',
936
        'smv' => 'video/x-smv',
937
        'smzip' => 'application/vnd.stepmania.package',
938
        'snd' => 'audio/basic',
939
        'snf' => 'application/x-font-snf',
940
        'so' => 'application/octet-stream',
941
        'spc' => 'application/x-pkcs7-certificates',
942
        'spdx' => 'text/spdx',
943
        'spf' => 'application/vnd.yamaha.smaf-phrase',
944
        'spl' => 'application/x-futuresplash',
945
        'spot' => 'text/vnd.in3d.spot',
946
        'spp' => 'application/scvp-vp-response',
947
        'spq' => 'application/scvp-vp-request',
948
        'spx' => 'audio/ogg',
949
        'sql' => 'application/x-sql',
950
        'src' => 'application/x-wais-source',
951
        'srt' => 'application/x-subrip',
952
        'sru' => 'application/sru+xml',
953
        'srx' => 'application/sparql-results+xml',
954
        'ssdl' => 'application/ssdl+xml',
955
        'sse' => 'application/vnd.kodak-descriptor',
956
        'ssf' => 'application/vnd.epson.ssf',
957
        'ssml' => 'application/ssml+xml',
958
        'sst' => 'application/octet-stream',
959
        'st' => 'application/vnd.sailingtracker.track',
960
        'stc' => 'application/vnd.sun.xml.calc.template',
961
        'std' => 'application/vnd.sun.xml.draw.template',
962
        'stf' => 'application/vnd.wt.stf',
963
        'sti' => 'application/vnd.sun.xml.impress.template',
964
        'stk' => 'application/hyperstudio',
965
        'stl' => 'model/stl',
966
        'str' => 'application/vnd.pg.format',
967
        'stw' => 'application/vnd.sun.xml.writer.template',
968
        'styl' => 'text/stylus',
969
        'stylus' => 'text/stylus',
970
        'sub' => 'text/vnd.dvb.subtitle',
971
        'sus' => 'application/vnd.sus-calendar',
972
        'susp' => 'application/vnd.sus-calendar',
973
        'sv4cpio' => 'application/x-sv4cpio',
974
        'sv4crc' => 'application/x-sv4crc',
975
        'svc' => 'application/vnd.dvb.service',
976
        'svd' => 'application/vnd.svd',
977
        'svg' => 'image/svg+xml',
978
        'svgz' => 'image/svg+xml',
979
        'swa' => 'application/x-director',
980
        'swf' => 'application/x-shockwave-flash',
981
        'swi' => 'application/vnd.aristanetworks.swi',
982
        'swidtag' => 'application/swid+xml',
983
        'sxc' => 'application/vnd.sun.xml.calc',
984
        'sxd' => 'application/vnd.sun.xml.draw',
985
        'sxg' => 'application/vnd.sun.xml.writer.global',
986
        'sxi' => 'application/vnd.sun.xml.impress',
987
        'sxm' => 'application/vnd.sun.xml.math',
988
        'sxw' => 'application/vnd.sun.xml.writer',
989
        't' => 'text/troff',
990
        't3' => 'application/x-t3vm-image',
991
        't38' => 'image/t38',
992
        'taglet' => 'application/vnd.mynfc',
993
        'tao' => 'application/vnd.tao.intent-module-archive',
994
        'tap' => 'image/vnd.tencent.tap',
995
        'tar' => 'application/x-tar',
996
        'tcap' => 'application/vnd.3gpp2.tcap',
997
        'tcl' => 'application/x-tcl',
998
        'td' => 'application/urc-targetdesc+xml',
999
        'teacher' => 'application/vnd.smart.teacher',
1000
        'tei' => 'application/tei+xml',
1001
        'teicorpus' => 'application/tei+xml',
1002
        'tex' => 'application/x-tex',
1003
        'texi' => 'application/x-texinfo',
1004
        'texinfo' => 'application/x-texinfo',
1005
        'text' => 'text/plain',
1006
        'tfi' => 'application/thraud+xml',
1007
        'tfm' => 'application/x-tex-tfm',
1008
        'tfx' => 'image/tiff-fx',
1009
        'tga' => 'image/x-tga',
1010
        'tgz' => 'application/x-tar',
1011
        'thmx' => 'application/vnd.ms-officetheme',
1012
        'tif' => 'image/tiff',
1013
        'tiff' => 'image/tiff',
1014
        'tk' => 'application/x-tcl',
1015
        'tmo' => 'application/vnd.tmobile-livetv',
1016
        'toml' => 'application/toml',
1017
        'torrent' => 'application/x-bittorrent',
1018
        'tpl' => 'application/vnd.groove-tool-template',
1019
        'tpt' => 'application/vnd.trid.tpt',
1020
        'tr' => 'text/troff',
1021
        'tra' => 'application/vnd.trueapp',
1022
        'trm' => 'application/x-msterminal',
1023
        'ts' => 'video/mp2t',
1024
        'tsd' => 'application/timestamped-data',
1025
        'tsv' => 'text/tab-separated-values',
1026
        'ttc' => 'font/collection',
1027
        'ttf' => 'font/ttf',
1028
        'ttl' => 'text/turtle',
1029
        'ttml' => 'application/ttml+xml',
1030
        'twd' => 'application/vnd.simtech-mindmapper',
1031
        'twds' => 'application/vnd.simtech-mindmapper',
1032
        'txd' => 'application/vnd.genomatix.tuxedo',
1033
        'txf' => 'application/vnd.mobius.txf',
1034
        'txt' => 'text/plain',
1035
        'u8dsn' => 'message/global-delivery-status',
1036
        'u8hdr' => 'message/global-headers',
1037
        'u8mdn' => 'message/global-disposition-notification',
1038
        'u8msg' => 'message/global',
1039
        'u32' => 'application/x-authorware-bin',
1040
        'ubj' => 'application/ubjson',
1041
        'udeb' => 'application/x-debian-package',
1042
        'ufd' => 'application/vnd.ufdl',
1043
        'ufdl' => 'application/vnd.ufdl',
1044
        'ulx' => 'application/x-glulx',
1045
        'umj' => 'application/vnd.umajin',
1046
        'unityweb' => 'application/vnd.unity',
1047
        'uoml' => 'application/vnd.uoml+xml',
1048
        'uri' => 'text/uri-list',
1049
        'uris' => 'text/uri-list',
1050
        'urls' => 'text/uri-list',
1051
        'usdz' => 'model/vnd.usdz+zip',
1052
        'ustar' => 'application/x-ustar',
1053
        'utz' => 'application/vnd.uiq.theme',
1054
        'uu' => 'text/x-uuencode',
1055
        'uva' => 'audio/vnd.dece.audio',
1056
        'uvd' => 'application/vnd.dece.data',
1057
        'uvf' => 'application/vnd.dece.data',
1058
        'uvg' => 'image/vnd.dece.graphic',
1059
        'uvh' => 'video/vnd.dece.hd',
1060
        'uvi' => 'image/vnd.dece.graphic',
1061
        'uvm' => 'video/vnd.dece.mobile',
1062
        'uvp' => 'video/vnd.dece.pd',
1063
        'uvs' => 'video/vnd.dece.sd',
1064
        'uvt' => 'application/vnd.dece.ttml+xml',
1065
        'uvu' => 'video/vnd.uvvu.mp4',
1066
        'uvv' => 'video/vnd.dece.video',
1067
        'uvva' => 'audio/vnd.dece.audio',
1068
        'uvvd' => 'application/vnd.dece.data',
1069
        'uvvf' => 'application/vnd.dece.data',
1070
        'uvvg' => 'image/vnd.dece.graphic',
1071
        'uvvh' => 'video/vnd.dece.hd',
1072
        'uvvi' => 'image/vnd.dece.graphic',
1073
        'uvvm' => 'video/vnd.dece.mobile',
1074
        'uvvp' => 'video/vnd.dece.pd',
1075
        'uvvs' => 'video/vnd.dece.sd',
1076
        'uvvt' => 'application/vnd.dece.ttml+xml',
1077
        'uvvu' => 'video/vnd.uvvu.mp4',
1078
        'uvvv' => 'video/vnd.dece.video',
1079
        'uvvx' => 'application/vnd.dece.unspecified',
1080
        'uvvz' => 'application/vnd.dece.zip',
1081
        'uvx' => 'application/vnd.dece.unspecified',
1082
        'uvz' => 'application/vnd.dece.zip',
1083
        'vbox' => 'application/x-virtualbox-vbox',
1084
        'vbox-extpack' => 'application/x-virtualbox-vbox-extpack',
1085
        'vcard' => 'text/vcard',
1086
        'vcd' => 'application/x-cdlink',
1087
        'vcf' => 'text/x-vcard',
1088
        'vcg' => 'application/vnd.groove-vcard',
1089
        'vcs' => 'text/x-vcalendar',
1090
        'vcx' => 'application/vnd.vcx',
1091
        'vdi' => 'application/x-virtualbox-vdi',
1092
        'vhd' => 'application/x-virtualbox-vhd',
1093
        'vis' => 'application/vnd.visionary',
1094
        'viv' => 'video/vnd.vivo',
1095
        'vlc' => 'application/videolan',
1096
        'vmdk' => 'application/x-virtualbox-vmdk',
1097
        'vob' => 'video/x-ms-vob',
1098
        'vor' => 'application/vnd.stardivision.writer',
1099
        'vox' => 'application/x-authorware-bin',
1100
        'vrml' => 'model/vrml',
1101
        'vsd' => 'application/vnd.visio',
1102
        'vsf' => 'application/vnd.vsf',
1103
        'vss' => 'application/vnd.visio',
1104
        'vst' => 'application/vnd.visio',
1105
        'vsw' => 'application/vnd.visio',
1106
        'vtf' => 'image/vnd.valve.source.texture',
1107
        'vtt' => 'text/vtt',
1108
        'vtu' => 'model/vnd.vtu',
1109
        'vxml' => 'application/voicexml+xml',
1110
        'w3d' => 'application/x-director',
1111
        'wad' => 'application/x-doom',
1112
        'wadl' => 'application/vnd.sun.wadl+xml',
1113
        'war' => 'application/java-archive',
1114
        'wasm' => 'application/wasm',
1115
        'wav' => 'audio/x-wav',
1116
        'wax' => 'audio/x-ms-wax',
1117
        'wbmp' => 'image/vnd.wap.wbmp',
1118
        'wbs' => 'application/vnd.criticaltools.wbs+xml',
1119
        'wbxml' => 'application/wbxml',
1120
        'wcm' => 'application/vnd.ms-works',
1121
        'wdb' => 'application/vnd.ms-works',
1122
        'wdp' => 'image/vnd.ms-photo',
1123
        'weba' => 'audio/webm',
1124
        'webapp' => 'application/x-web-app-manifest+json',
1125
        'webm' => 'video/webm',
1126
        'webmanifest' => 'application/manifest+json',
1127
        'webp' => 'image/webp',
1128
        'wg' => 'application/vnd.pmi.widget',
1129
        'wgt' => 'application/widget',
1130
        'wks' => 'application/vnd.ms-works',
1131
        'wm' => 'video/x-ms-wm',
1132
        'wma' => 'audio/x-ms-wma',
1133
        'wmd' => 'application/x-ms-wmd',
1134
        'wmf' => 'image/wmf',
1135
        'wml' => 'text/vnd.wap.wml',
1136
        'wmlc' => 'application/wmlc',
1137
        'wmls' => 'text/vnd.wap.wmlscript',
1138
        'wmlsc' => 'application/vnd.wap.wmlscriptc',
1139
        'wmv' => 'video/x-ms-wmv',
1140
        'wmx' => 'video/x-ms-wmx',
1141
        'wmz' => 'application/x-msmetafile',
1142
        'woff' => 'font/woff',
1143
        'woff2' => 'font/woff2',
1144
        'word' => 'application/msword',
1145
        'wpd' => 'application/vnd.wordperfect',
1146
        'wpl' => 'application/vnd.ms-wpl',
1147
        'wps' => 'application/vnd.ms-works',
1148
        'wqd' => 'application/vnd.wqd',
1149
        'wri' => 'application/x-mswrite',
1150
        'wrl' => 'model/vrml',
1151
        'wsc' => 'message/vnd.wfa.wsc',
1152
        'wsdl' => 'application/wsdl+xml',
1153
        'wspolicy' => 'application/wspolicy+xml',
1154
        'wtb' => 'application/vnd.webturbo',
1155
        'wvx' => 'video/x-ms-wvx',
1156
        'x3d' => 'model/x3d+xml',
1157
        'x3db' => 'model/x3d+fastinfoset',
1158
        'x3dbz' => 'model/x3d+binary',
1159
        'x3dv' => 'model/x3d-vrml',
1160
        'x3dvz' => 'model/x3d+vrml',
1161
        'x3dz' => 'model/x3d+xml',
1162
        'x32' => 'application/x-authorware-bin',
1163
        'x_b' => 'model/vnd.parasolid.transmit.binary',
1164
        'x_t' => 'model/vnd.parasolid.transmit.text',
1165
        'xaml' => 'application/xaml+xml',
1166
        'xap' => 'application/x-silverlight-app',
1167
        'xar' => 'application/vnd.xara',
1168
        'xav' => 'application/xcap-att+xml',
1169
        'xbap' => 'application/x-ms-xbap',
1170
        'xbd' => 'application/vnd.fujixerox.docuworks.binder',
1171
        'xbm' => 'image/x-xbitmap',
1172
        'xca' => 'application/xcap-caps+xml',
1173
        'xcs' => 'application/calendar+xml',
1174
        'xdf' => 'application/xcap-diff+xml',
1175
        'xdm' => 'application/vnd.syncml.dm+xml',
1176
        'xdp' => 'application/vnd.adobe.xdp+xml',
1177
        'xdssc' => 'application/dssc+xml',
1178
        'xdw' => 'application/vnd.fujixerox.docuworks',
1179
        'xel' => 'application/xcap-el+xml',
1180
        'xenc' => 'application/xenc+xml',
1181
        'xer' => 'application/xcap-error+xml',
1182
        'xfdf' => 'application/vnd.adobe.xfdf',
1183
        'xfdl' => 'application/vnd.xfdl',
1184
        'xht' => 'application/xhtml+xml',
1185
        'xhtml' => 'application/xhtml+xml',
1186
        'xhvml' => 'application/xv+xml',
1187
        'xif' => 'image/vnd.xiff',
1188
        'xl' => 'application/excel',
1189
        'xla' => 'application/vnd.ms-excel',
1190
        'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
1191
        'xlc' => 'application/vnd.ms-excel',
1192
        'xlf' => 'application/xliff+xml',
1193
        'xlm' => 'application/vnd.ms-excel',
1194
        'xls' => 'application/vnd.ms-excel',
1195
        'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
1196
        'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
1197
        'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
1198
        'xlt' => 'application/vnd.ms-excel',
1199
        'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
1200
        'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
1201
        'xlw' => 'application/vnd.ms-excel',
1202
        'xm' => 'audio/xm',
1203
        'xml' => 'application/xml',
1204
        'xns' => 'application/xcap-ns+xml',
1205
        'xo' => 'application/vnd.olpc-sugar',
1206
        'xop' => 'application/xop+xml',
1207
        'xpi' => 'application/x-xpinstall',
1208
        'xpl' => 'application/xproc+xml',
1209
        'xpm' => 'image/x-xpixmap',
1210
        'xpr' => 'application/vnd.is-xpr',
1211
        'xps' => 'application/vnd.ms-xpsdocument',
1212
        'xpw' => 'application/vnd.intercon.formnet',
1213
        'xpx' => 'application/vnd.intercon.formnet',
1214
        'xsd' => 'application/xml',
1215
        'xsl' => 'application/xml',
1216
        'xslt' => 'application/xslt+xml',
1217
        'xsm' => 'application/vnd.syncml+xml',
1218
        'xspf' => 'application/xspf+xml',
1219
        'xul' => 'application/vnd.mozilla.xul+xml',
1220
        'xvm' => 'application/xv+xml',
1221
        'xvml' => 'application/xv+xml',
1222
        'xwd' => 'image/x-xwindowdump',
1223
        'xyz' => 'chemical/x-xyz',
1224
        'xz' => 'application/x-xz',
1225
        'yaml' => 'text/yaml',
1226
        'yang' => 'application/yang',
1227
        'yin' => 'application/yin+xml',
1228
        'yml' => 'text/yaml',
1229
        'ymp' => 'text/x-suse-ymp',
1230
        'z' => 'application/x-compress',
1231
        'z1' => 'application/x-zmachine',
1232
        'z2' => 'application/x-zmachine',
1233
        'z3' => 'application/x-zmachine',
1234
        'z4' => 'application/x-zmachine',
1235
        'z5' => 'application/x-zmachine',
1236
        'z6' => 'application/x-zmachine',
1237
        'z7' => 'application/x-zmachine',
1238
        'z8' => 'application/x-zmachine',
1239
        'zaz' => 'application/vnd.zzazz.deck+xml',
1240
        'zip' => 'application/x-zip',
1241
        'zir' => 'application/vnd.zul',
1242
        'zirz' => 'application/vnd.zul',
1243
        'zmm' => 'application/vnd.handheld-entertainment+xml',
1244
        'zsh' => 'text/x-scriptzsh',
1245
    ];
1246
1247
    /**
1248
     * List contents of a directory.
1249
     *
1250
     * @param string $directory The directory to list.
1251
     * @param bool   $recursive Whether to list recursively.
1252
     *
1253
     * @return array A list of file metadata.
1254
     */
1255
    public static function listContents(string $directory = '', bool $recursive = false) : array
1256
    {
1257
        $result = [];
1258
1259
        if (! is_dir($directory)) {
1260
            return [];
1261
        }
1262
1263
        $iterator = $recursive ? self::getRecursiveDirectoryIterator($directory) : self::getDirectoryIterator($directory);
1264
1265
        foreach ($iterator as $file) {
1266
            $path = self::getFilePath($file);
1267
1268
            if (preg_match('#(^|/|\\\\)\.{1,2}$#', $path)) {
1269
                continue;
1270
            }
1271
1272
            $result[] = self::normalizeFileInfo($file);
1273
        }
1274
1275
        return array_filter($result);
1276
    }
1277
1278
    /**
1279
     * Get directory timestamp
1280
     *
1281
     * @param string $directory The directory
1282
     *
1283
     * @return int directory timestamp
1284
     */
1285
    public static function getDirTimestamp(string $directory) : int
1286
    {
1287
        $_directory  = new RecursiveDirectoryIterator(
1288
            $directory,
1289
            FilesystemIterator::KEY_AS_PATHNAME |
1290
            FilesystemIterator::CURRENT_AS_FILEINFO |
1291
            FilesystemIterator::SKIP_DOTS
1292
        );
1293
        $_iterator   = new RecursiveIteratorIterator(
1294
            $_directory,
1295
            RecursiveIteratorIterator::SELF_FIRST
1296
        );
1297
        $_resultFile = $_iterator->current();
1298
        foreach ($_iterator as $file) {
1299
            if ($file->getMtime() <= $_resultFile->getMtime()) {
1300
                continue;
1301
            }
1302
1303
            $_resultFile = $file;
1304
        }
1305
1306
        return $_resultFile->getMtime();
1307
    }
1308
1309
    /**
1310
     * Returns the mime type of a file. Returns false if the mime type is not found.
1311
     *
1312
     * @param  string $file  Full path to the file
1313
     * @param  bool   $guess Set to false to disable mime type guessing
1314
     *
1315
     * @return mixed
1316
     */
1317
    public static function getMimeType(string $file, bool $guess = true)
1318
    {
1319
        // Get mime using the file information functions
1320
        if (function_exists('finfo_open')) {
1321
            $info = finfo_open(FILEINFO_MIME_TYPE);
1322
1323
            $mime = finfo_file($info, $file);
1324
1325
            finfo_close($info);
1326
1327
            return $mime;
1328
        }
1329
1330
        // Just guess mime by using the file extension
1331
        if ($guess === true) {
1332
            $mime_types = self::$mime_types;
1333
1334
            $extension = pathinfo($file, PATHINFO_EXTENSION);
1335
1336
            return $mime_types[$extension] ?? false;
1337
        }
1338
1339
        return false;
1340
    }
1341
1342
    /**
1343
     * Get a file's timestamp.
1344
     *
1345
     * @param string $path The path to the file.
1346
     *
1347
     * @return string|false The timestamp or false on failure.
1348
     */
1349
    public static function getTimestamp(string $path)
1350
    {
1351
        return self::getMetadata($path)['timestamp'];
1352
    }
1353
1354
    /**
1355
     * Get a file's size.
1356
     *
1357
     * @param string $path The path to the file.
1358
     *
1359
     * @return int|false The file size or false on failure.
1360
     */
1361
    public static function getSize(string $path)
1362
    {
1363
        return self::getMetadata($path)['size'];
1364
    }
1365
1366
    /**
1367
     * Get a file's metadata.
1368
     *
1369
     * @param string $path The path to the file.
1370
     *
1371
     * @return array|false The file metadata or false on failure.
1372
     */
1373
    public static function getMetadata(string $path)
1374
    {
1375
        $info = new SplFileInfo($path);
1376
1377
        return self::normalizeFileInfo($info);
1378
    }
1379
1380
    /**
1381
     * Get a file's visibility.
1382
     *
1383
     * @param string $path The path to the file.
1384
     *
1385
     * @return string|false The visibility (public|private) or false on failure.
1386
     */
1387
    public static function getVisibility(string $path)
1388
    {
1389
        clearstatcache(false, $path);
1390
        $permissions = octdec(substr(sprintf('%o', fileperms($path)), -4));
1391
1392
        return $permissions & 0044 ? 'public' : 'private';
1393
    }
1394
1395
    /**
1396
     * Set the visibility for a file.
1397
     *
1398
     * @param string $path       The path to the file.
1399
     * @param string $visibility One of 'public' or 'private'.
1400
     *
1401
     * @return bool True on success, false on failure.
1402
     */
1403
    public static function setVisibility(string $path, string $visibility) : bool
1404
    {
1405
        $type    = is_dir($path) ? 'dir' : 'file';
1406
        $success = chmod($path, self::$permissions[$type][$visibility]);
1407
1408
        return $success !== false;
1409
    }
1410
1411
    /**
1412
     * Delete a file.
1413
     *
1414
     * @return bool True on success, false on failure.
1415
     */
1416
    public static function delete(string $path) : bool
1417
    {
1418
        if (self::has($path)) {
1419
            $result = unlink($path);
1420
1421
            // Wiping out changes in local file cache
1422
            clearstatcache(false, $path);
1423
1424
            return $result;
1425
        }
1426
1427
        return false;
1428
    }
1429
1430
    /**
1431
     * Delete a directory.
1432
     *
1433
     * @return bool True on success, false on failure.
1434
     */
1435
    public static function deleteDir(string $dirname) : bool
1436
    {
1437
        if (! is_dir($dirname)) {
1438
            return false;
1439
        }
1440
1441
        // Delete dir
1442
        if (is_dir($dirname)) {
1443
            $ob = scandir($dirname);
1444
            foreach ($ob as $o) {
1445
                if ($o === '.' || $o === '..') {
1446
                    continue;
1447
                }
1448
1449
                if (filetype($dirname . '/' . $o) === 'dir') {
1450
                    self::deleteDir($dirname . '/' . $o);
1451
                } else {
1452
                    self::delete($dirname . '/' . $o);
1453
                }
1454
            }
1455
        }
1456
1457
        reset($ob);
1458
        rmdir($dirname);
1459
1460
        return true;
1461
    }
1462
1463
    /**
1464
     * Create a directory.
1465
     *
1466
     * @param string $dirname    The name of the new directory.
1467
     * @param string $visibility Visibility
1468
     *
1469
     * @return bool True on success, false on failure.
1470
     */
1471
    public static function createDir(string $dirname, string $visibility = 'public') : bool
1472
    {
1473
        $umask = umask(0);
1474
1475
        if (! is_dir($dirname) && ! mkdir($dirname, self::$permissions['dir'][$visibility], true)) {
1476
            return false;
1477
        }
1478
1479
        umask($umask);
1480
1481
        return true;
1482
    }
1483
1484
    /**
1485
     * Copy a file(s).
1486
     *
1487
     * @param string $path      Path to the existing file.
1488
     * @param string $newpath   The new path of the file.
1489
     * @param bool   $recursive Recursive copy files.
1490
     *
1491
     * @return bool True on success, false on failure.
1492
     */
1493
    public static function copy(string $path, string $newpath, bool $recursive = false)
1494
    {
1495
        if (! $recursive) {
1496
            return copy($path, $newpath);
1497
        }
1498
1499
        if (! self::has($newpath)) {
1500
            mkdir($newpath);
1501
        }
1502
1503
        $splFileInfoArr = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
1504
1505
        foreach ($splFileInfoArr as $fullPath => $splFileinfo) {
1506
            //skip . ..
1507
            if (in_array($splFileinfo->getBasename(), ['.', '..'])) {
1508
                continue;
1509
            }
1510
1511
            //get relative path of source file or folder
1512
            $_path = str_replace($path, '', $splFileinfo->getPathname());
1513
1514
            if ($splFileinfo->isDir()) {
1515
                mkdir($newpath . '/' . $_path);
1516
            } else {
1517
                copy($fullPath, $newpath . '/' . $_path);
1518
            }
1519
        }
1520
    }
1521
1522
    /**
1523
     * Rename a file.
1524
     *
1525
     * @param string $path    Path to the existing file.
1526
     * @param string $newpath The new path of the file.
1527
     *
1528
     * @return bool True on success, false on failure.
1529
     */
1530
    public static function rename(string $path, string $newpath) : bool
1531
    {
1532
        return rename($path, $newpath);
1533
    }
1534
1535
    /**
1536
     * Write a file.
1537
     *
1538
     * @param string $path       The path of the new file.
1539
     * @param string $contents   The file contents.
1540
     * @param string $visibility An optional configuration array.
1541
     * @param int    $flags      Flags
1542
     *
1543
     * @return bool True on success, false on failure.
1544
     */
1545
    public static function write(string $path, string $contents, string $visibility = 'public', int $flags = LOCK_EX) : bool
1546
    {
1547
        if (file_put_contents($path, $contents, $flags) === false) {
1548
            return false;
1549
        }
1550
1551
        self::setVisibility($path, $visibility);
1552
1553
        return true;
1554
    }
1555
1556
    /**
1557
     * Check whether a file exists.
1558
     */
1559
    public static function has(string $path) : bool
1560
    {
1561
        return file_exists($path);
1562
    }
1563
1564
    /**
1565
     * Read a file.
1566
     *
1567
     * @param string $path The path to the file.
1568
     *
1569
     * @return string|false The file contents or false on failure.
1570
     */
1571
    public static function read(string $path)
1572
    {
1573
        $contents = file_get_contents($path);
1574
1575
        if ($contents === false) {
1576
            return false;
1577
        }
1578
1579
        return $contents;
1580
    }
1581
1582
    /**
1583
     * Normalize the file info.
1584
     *
1585
     * @return array|void
1586
     */
1587
    protected static function normalizeFileInfo(SplFileInfo $file)
1588
    {
1589
        return self::mapFileInfo($file);
1590
    }
1591
1592
    /**
1593
     * @return array
1594
     */
1595
    protected static function mapFileInfo(SplFileInfo $file) : array
1596
    {
1597
        $normalized = [
1598
            'type' => $file->getType(),
1599
            'path' => self::getFilePath($file),
1600
        ];
1601
1602
        $normalized['timestamp'] = $file->getMTime();
1603
1604
        if ($normalized['type'] === 'file') {
1605
            $normalized['size']      = $file->getSize();
1606
            $normalized['filename']  = $file->getFilename();
1607
            $normalized['basename']  = $file->getBasename('.' . $file->getExtension());
1608
            $normalized['extension'] = $file->getExtension();
1609
        }
1610
1611
        if ($normalized['type'] === 'dir') {
1612
            $normalized['dirname'] = $file->getFilename();
1613
        }
1614
1615
        return $normalized;
1616
    }
1617
1618
    /**
1619
     * Get the normalized path from a SplFileInfo object.
1620
     */
1621
    protected static function getFilePath(SplFileInfo $file) : string
1622
    {
1623
        $path = $file->getPathname();
1624
1625
        $path = trim(str_replace('\\', '/', $path));
1626
1627
        return $path;
1628
    }
1629
1630
    protected static function getRecursiveDirectoryIterator(string $path, int $mode = RecursiveIteratorIterator::SELF_FIRST) : RecursiveIteratorIterator
1631
    {
1632
        return new RecursiveIteratorIterator(
1633
            new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS),
1634
            $mode
1635
        );
1636
    }
1637
1638
    protected static function getDirectoryIterator(string $path) : \DirectoryIterator
1639
    {
1640
        return new \DirectoryIterator($path);
1641
    }
1642
}
1643