-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.php
More file actions
26 lines (24 loc) · 770 Bytes
/
index.php
File metadata and controls
26 lines (24 loc) · 770 Bytes
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
<?php
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
http_response_code(401);
die();
}
$method = $_SERVER['REQUEST_METHOD'];
$file_name = md5($_SERVER['PHP_AUTH_USER'].':'.$_SERVER['PHP_AUTH_PW']).'.json';
$file = dirname(__FILE__).'/store/'.$file_name;
header('Content-type: application/json');
if ($method == 'GET') {
if (!file_exists($file)) {
http_response_code(404);
echo json_encode(array('error' => 'not found'));
die();
}
readfile($file);
} else if ($method == 'POST') {
file_put_contents($file, file_get_contents('php://input'));
echo json_encode(array('status' => 'ok'));
} else {
http_response_code(405);
echo json_encode(array('error' => 'method not allowed'));
}
?>