-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
50 lines (49 loc) · 1.02 KB
/
index.php
File metadata and controls
50 lines (49 loc) · 1.02 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
47
48
49
50
<?php
$file = explode('=',$_SERVER['QUERY_STRING'])[1];
switch($_SERVER['REQUEST_METHOD'])
{
case 'HEAD':
if (file_exists($file))
{
// 'head' responce has no body, so size of file can be placed in http header
header('Content-Length: '.filesize($file));
}
break;
case 'GET':
if (file_exists($file))
{
$handle = fopen($file, 'r');
fpassthru($handle);
fclose($handle);
}
break;
case 'POST':
if (file_exists($file))
{
$requestBody = file_get_contents('php://input');
$handle = fopen($file, 'w');
flock($handle, LOCK_EX);
fwrite($handle, $requestBody);
flock($handle, LOCK_UN);
fclose($handle);
}
break;
case 'DELETE':
if (file_exists($file))
{
unlink($file);
}
break;
case 'PATCH':
if (file_exists($file))
{
$requestBody = file_get_contents('php://input');
$handle = fopen($file, 'a');
flock($handle, LOCK_EX);
fwrite ($handle, $requestBody);
flock($handle, LOCK_UN);
fclose($handle);
}
break;
}
?>