-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
52 lines (43 loc) · 1.07 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
<?php
/*
php builtin server command
------------------------------------
php -S 127.0.0.1:8080 -t . index.php
------------------------------------
-S [address]:[port]
-S 127.0.0.1:8080
-t [root directory] [router file]
-t . index.php
*/
/*
markdown viewer - firefox plugin
------------------------------------
https://github.com/Thiht/markdown-viewer
------------------------------------
*/
// markdown file extension
$file_ext = ".md";
// ------------------------------------
// routing
// ------------------------------------
// parse url
$filename = parse_url(
$_SERVER["REQUEST_URI"],
PHP_URL_PATH
);
// remove leading '/' character
$filename = preg_replace('/^[\/]/', '', $filename);
// close open parenthesis '(' character
$filename = preg_replace('/[\(]$/', '()', $filename);
// var_dump($filename);
// die();
if ( substr($filename, -3) !== $file_ext ) {
$filename .= $file_ext;
header("Location: /".$filename);
exit;
}
// print file
$file = file_get_contents($filename);
header('Content-type: text/plain');
echo $file;
?>