-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathserver.php
More file actions
46 lines (36 loc) · 1.3 KB
/
server.php
File metadata and controls
46 lines (36 loc) · 1.3 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
<?php
if (!class_exists('FileServer')) {
class FileServer {
private static $available = null;
static function output($path) {
if (self::$available === null) {
self::$available = parse_ini_file('server.ini');
}
// Check if the file exists
if(empty(self::$available[$path]) || !is_file($path)) {
header('HTTP/1.0 404 Not Found');
exit();
}
$mTime = filemtime($path);
$fileModificationTime = gmdate('D, d M Y H:i:s', $mTime).' GMT';
$etag = base_convert($mTime, 10, 32);
// Set headers
header('Access-Control-Allow-Origin: "*"');
header('Content-Type: '.mime_content_type($path).'; charset=utf-8');
header('Last-Modified: '.$fileModificationTime);
header('ETag: "' . $etag . '"');
// Handle caching
if(!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $mTime) {
header('HTTP/1.1 304 Not Modified');
exit();
}
// Read the file
@readfile($path);
exit();
}
}
}
if (!empty($_GET['file'])) {
FileServer::output((string)$_GET['file']);
}
?>