-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
96 lines (94 loc) · 4.1 KB
/
index.php
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
91
92
93
94
95
96
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
$root = dirname(__FILE__) . DIRECTORY_SEPARATOR;
require_once $root . "rewrite" . DIRECTORY_SEPARATOR . "Rewrite.php";
$path = $_SERVER['REQUEST_URI'];
if(!Rewrite::match($path)){
if(($pos = strpos($path, '?')) !== false){
$path = substr($path, 0, $pos);
}
if('/' === $path){
echo 'index';
} else {
$len = strlen($path) - 1;
if('/' === $path{$len}){
$path = substr($path, 0, $len);
}
$split = explode('/', $path);
if('static' === $split[1]){
$file = $root . substr($path, 1);
if(is_file($file)){
$content_type = 'Content-Type: ';
$pos = strrpos($file, '.');
if(false !== $pos){
$ext = substr($file, $pos + 1);
$MIME = array(
'bmp' => 'image/bmp',
'css' => 'text/css',
'doc' => 'application/msword',
'dtd' => 'text/xml',
'gif' => 'image/gif',
'hta' => 'application/hta',
'htc' => 'text/x-component',
'htm' => 'text/html',
'html' => 'text/html',
'xhtml' => 'text/html',
'tpl' => 'text/html',
'ico' => 'image/x-icon',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'js' => 'text/javascript',
'json' => 'application/json',
'jsp' => 'text/html',
'mocha' => 'text/javascript',
'mp3' => 'audio/mp3',
'mp4' => 'video/mpeg4',
'mpeg' => 'video/mpg',
'mpg' => 'video/mpg',
'manifest' => 'text/cache-manifest',
'pdf' => 'application/pdf',
'png' => 'image/png',
'ppt' => 'application/vnd.ms-powerpoint',
'rmvb' => 'application/vnd.rn-realmedia-vbr',
'rm' => 'application/vnd.rn-realmedia',
'rtf' => 'application/msword',
'svg' => 'image/svg+xml',
'swf' => 'application/x-shockwave-flash',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'txt' => 'text/plain',
'vml' => 'text/xml',
'vxml' => 'text/xml',
'wav' => 'audio/wav',
'wma' => 'audio/x-ms-wma',
'wmv' => 'video/x-ms-wmv',
'xml' => 'text/xml',
'xls' => 'application/vnd.ms-excel',
'xq' => 'text/xml',
'xql' => 'text/xml',
'xquery' => 'text/xml',
'xsd' => 'text/xml',
'xsl' => 'text/xml',
'xslt' => 'text/xml'
);
$content_type .= $MIME[$ext] ? $MIME[$ext] : 'application/x-' . $ext;
} else {
$content_type .= 'text/plain';
}
header($content_type);
echo file_get_contents($file);
} else {
header('Status: 404 File Not Found');
}
} else {
$last = array_pop($split);
$len = count($split);
$file = $root . 'template' . $path;
$content_type = 'Content-Type: text/html';
header($content_type);
echo file_get_contents($file);
}
}
}