-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.php
More file actions
64 lines (55 loc) · 1.64 KB
/
server.php
File metadata and controls
64 lines (55 loc) · 1.64 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
<?php
/**
* Here is the serverless function entry
* for deployment with Vercel.
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ?? ''
);
if ($uri !== '/' && file_exists($file = __DIR__.'/public'.$uri)) {
header('Content-type: '.get_mime_type($file).'; charset: UTF-8;');
readfile($file);
} else {
require_once __DIR__.'/public/index.php';
}
function get_mime_type($filename) {
$extension = strtolower(pathinfo($filename)['extension']);
$mimes = array(
'txt' => 'text/plain',
'html' => 'text/html',
'php' => 'text/html',
'css' => 'text/css',
'js' => 'application/javascript',
'json' => 'application/json',
'xml' => 'application/xml',
// images
'png' => 'image/png',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'webp' => 'image/webp',
'gif' => 'image/gif',
'bmp' => 'image/bmp',
'ico' => 'image/vnd.microsoft.icon',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',
// archives
'zip' => 'application/zip',
'rar' => 'application/x-rar-compressed',
// audio/video
'mp3' => 'audio/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
// fonts
'ttf' => 'application/x-font-ttf',
'woff' => 'application/x-woff',
'woff2' => 'font/woff2',
'otf' => 'font/otf',
);
if (isset($mimes[$extension])) {
return $mimes[$extension];
}
return 'application/octet-stream';
}