-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.php
51 lines (41 loc) · 1.32 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
<?php
require 'vendor/autoload.php';
use Pux\Mux;
use Pux\Executor;
class FilesController {
public function getFileInfoAction($name) {
$path = "office/$name";
if (file_exists($path)) {
$handle = fopen($path, "r");
$size = filesize($path);
$contents = fread($handle, $size);
$SHA256 = base64_encode(hash('sha256', $contents, true));
$json = array(
'BaseFileName' => $name,
'OwnerId' => 'admin',
'Size' => $size,
'SHA256' => $SHA256,
'Version' => '222888822'
);
echo json_encode($json);
} else {
echo json_encode(array());
}
}
public function getFileAction($name) {
$path = "office/$name";
if (file_exists($path)) {
$handle = fopen($path, "r");
$contents = fread($handle, filesize($path));
header("Content-type: application/octet-stream");
echo $contents;
}
}
}
$mux = new Mux;
$mux->get('/files/:name', ['FilesController','getFileInfoAction']);
$mux->get('/files/:name/contents', ['FilesController','getFileAction']);
$path = $_SERVER['PATH_INFO'];
$args = explode("&", $path);
$route = $mux->dispatch( $args[0] );
Executor::execute($route);